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 | 809 | 2026/3/31 |
| 0.21.99 | 3,282 | 2025/5/7 |
| 0.21.98 | 339 | 2025/4/30 |
| 0.20.74 | 10,217 | 2024/2/3 |
| 0.19.67 | 1,710 | 2023/10/12 |
| 0.19.66 | 2,301 | 2023/6/8 |
| 0.18.54 | 3,427 | 2023/1/27 |
| 0.18.48 | 1,991 | 2022/12/30 |
| 0.18.47 | 4,964 | 2022/8/26 |
| 0.18.46 | 889 | 2022/8/26 |
| 0.18.45 | 889 | 2022/8/26 |
| 0.18.43 | 904 | 2022/8/22 |
| 0.18.42 | 2,993 | 2022/6/1 |
| 0.17.40 | 4,276 | 2022/1/21 |
| 0.17.39 | 854 | 2022/1/11 |
| 0.16.36 | 1,440 | 2021/11/17 |
| 0.15.30 | 2,150 | 2021/8/5 |
| 0.14.26 | 1,024 | 2021/3/13 |
| 0.13.18 | 2,355 | 2020/6/17 |