Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyone know of a simple C interpreter written in C#? [closed]

Tags:

c

c#

interpreter

About 13 years ago I needed a way to script an application I was writing in Borland C++. I found a C interpreter and embedded that in my application. This has been working fine and I have quite a number of scripts.

I now need to rework the app and will do this in C#. Does anyone know of a C interpreter for C#? I have the sources for the original interpreter but I just need to save some time.

Edit Here is an extract from a script:

main()
{
   LwSet( "STUFE", "00.00" );
   LwSet( "STATUS", "Warten", "AUS" );
   do
   {
      LwSet( "DEBUG", "OFF" );
      LwSet( "FUNKTION", "Warten auf Start" );
      do
      {
         rc = LwGet( "Event" );
         if( rc == "QUIT" ) {
            ...

The LwSet/LwGet calls a functions which I registered with the interpreter and are features of my application.

Edit2

Before anyone feels the need to tell me what other language I should have used, here is my comment from below:

At the time, and considering the skills available it was not an annoying choice. Now, 13 years later, a lot of things look a whole lot different! I'm just stuck with a pile of quasi-C scripts which I would like to use without having to convert them all somehow.

like image 674
paul Avatar asked Apr 07 '11 11:04

paul


People also ask

How do you write a simple interpreter?

To create an interpreter first you need to create a lexer to get the tokens of your input program. Next you create a parser that takes those tokens and, by following the rules of a formal grammar, returns an AST of your input program. Finally, the interpreter takes that AST and interprets it in some way.

Is there an interpreter for C?

Programming languages like JavaScript, Python, Ruby use interpreters. Programming languages like C, C++, Java use compilers.


4 Answers

How about using the same existing C interpreter from C# via interop?

like image 67
Justin Avatar answered Nov 15 '22 06:11

Justin


The excellent ANTLR parser generator has support for C#. Its examples include a C grammar for C#.

This obviously isn't a full interpreter, but the grammar, lexer and parser would make a good starting point.

like image 39
Josh Kelley Avatar answered Nov 15 '22 07:11

Josh Kelley


I don't know of any C interpreter for C# but there is a c# scripting engine that you might be able to use.

http://www.csscript.net/index.html

like image 31
Alex Mendez Avatar answered Nov 15 '22 06:11

Alex Mendez


The nearist think I'm aware of is: http://www.softintegration.com/

Added the following Link Is there an interpreter for C?

Regards Friedrich

like image 2
Friedrich Avatar answered Nov 15 '22 08:11

Friedrich