Skip to main content
CLanguage package icon

CLanguage

v0.23.230Latest Stable
net10.0.NETStandard2.0

C parser, compiler, and interpreter.

Published
Oct 1, 2026
1mo ago
Total Downloads
113.2K
113,195

Install

dotnet add package CLanguage --version 0.23.230
ProductVersions
.NET
net10.0
.NET Standard
netstandard2.0

README

CLanguage

NuGet Package

CLanguage is a .NET Standard library that contains a C/C++ parser, a compiler (to its own VM), and an interpreter (for its VM). It's a very small library that enables you to embed C/C++ scripts into your .NET apps.

It is used to simulate Arduinos in the app iCircuit. It features cycle counting so that infinite loops and long computations can be paused.

I describe other details of it in my blog entry Oops, I Wrote a C++ Compiler.

Usage

There are two stages:

  1. Compiling using CLanguage.Compiler.CCompiler
  2. Interpreting using CLanguage.Interpreter.CInterpreter

Machine information, such as pointer sizes, is stored in MachineInfo objects.

After compilation, you must create an interpreter, Reset it, then Run it.

Simple Evaluation

There is a static Eval method on CLanguageService to make compiling and executing expressions easier than setting everything up manually.

For example:

var result = CLanguageService.Eval("2 + 3");
Assert.AreEqual(5, result);

Parsing Header Files

You can use CLanguageService.ParseTranslationUnit() to parse C/C++ header files and extract struct/enum definitions, global variables, function declarations, and typedefs without compiling to bytecode.

using CLanguage;
using CLanguage.Syntax;

var code = File.ReadAllText("myheader.h");
TranslationUnit tu = CLanguageService.ParseTranslationUnit(code);

// Struct/class definitions
foreach (var (name, structType) in tu.Structures)
{
    Console.WriteLine($"struct {name}:");
    foreach (var member in structType.Members)
        Console.WriteLine($"  {member.Name}: {member.MemberType}");
}

// Enum definitions
foreach (var (name, enumType) in tu.Enums)
{
    Console.WriteLine($"enum {name}:");
    foreach (var member in enumType.Members)
        Console.WriteLine($"  {member.Name} = {member.Value}");
}

// Global variables
foreach (var variable in tu.Variables)
    Console.WriteLine($"var {variable.Name}: {variable.VariableType}");

// Function declarations
foreach (var func in tu.Functions)
    Console.WriteLine($"func {func.Name}: {func.FunctionType}");

// Typedefs
foreach (var (name, type) in tu.Typedefs)
    Console.WriteLine($"typedef {name} = {type}");

Key types you can inspect:

  • CStructType.Members β€” list of CStructField (with Name, MemberType) and CStructMethod entries
  • CEnumType.Members β€” list of CEnumMember (with Name, Value)
  • CFunctionType β€” has ReturnType and Parameters (each with Name and ParameterType)
  • CompiledVariable β€” has Name and VariableType

If you need system headers resolved (e.g., #include <stdint.h>), use the CParser directly and provide an include callback.

Changes from Previous Version

v0.22.225v0.23.230
Added Frameworks
net10.0
Removed Frameworks
net9.0

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.