CLanguage 0.22.225
dotnet add package CLanguage --version 0.22.225
NuGet\Install-Package CLanguage -Version 0.22.225
<PackageReference Include="CLanguage" Version="0.22.225" />
<PackageVersion Include="CLanguage" Version="0.22.225" />
<PackageReference Include="CLanguage" />
paket add CLanguage --version 0.22.225
#r "nuget: CLanguage, 0.22.225"
#:package CLanguage@0.22.225
#addin nuget:?package=CLanguage&version=0.22.225
#tool nuget:?package=CLanguage&version=0.22.225
CLanguage
<img src="https://github.com/praeclarum/CLanguage/raw/master/Documentation/Icon.png" height="20">
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:
- Compiling using
CLanguage.Compiler.CCompiler - 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 ofCStructField(withName,MemberType) andCStructMethodentriesCEnumType.Members— list ofCEnumMember(withName,Value)CFunctionType— hasReturnTypeandParameters(each withNameandParameterType)CompiledVariable— hasNameandVariableType
If you need system headers resolved (e.g., #include <stdint.h>), use the CParser directly and provide an include callback.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CLanguage:
| Package | Downloads |
|---|---|
|
CLanguage.Editor
C parser, compiler, and interpreter. |
|
|
IoTSharp.Interpreter
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on CLanguage:
| Repository | Stars |
|---|---|
|
IoTSharp/IoTSharp
IoTSharp is an open-source IoT platform for data collection, processing, visualization, and device management.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 0.22.225 | 44 | 3/31/2026 |
| 0.21.99 | 2,730 | 5/7/2025 |
| 0.21.98 | 308 | 4/30/2025 |
| 0.20.74 | 10,031 | 2/3/2024 |
| 0.19.67 | 1,676 | 10/12/2023 |
| 0.19.66 | 2,261 | 6/8/2023 |
| 0.18.54 | 3,382 | 1/27/2023 |
| 0.18.48 | 1,956 | 12/30/2022 |
| 0.18.47 | 4,908 | 8/26/2022 |
| 0.18.46 | 862 | 8/26/2022 |
| 0.18.45 | 861 | 8/26/2022 |
| 0.18.43 | 872 | 8/22/2022 |
| 0.18.42 | 2,963 | 6/1/2022 |
| 0.17.40 | 4,234 | 1/21/2022 |
| 0.17.39 | 816 | 1/11/2022 |
| 0.16.36 | 1,405 | 11/17/2021 |
| 0.15.30 | 2,117 | 8/5/2021 |
| 0.14.26 | 991 | 3/13/2021 |
| 0.13.18 | 2,324 | 6/17/2020 |