Is there any C interpreter written in javascript or java ?
I don't need a full interpreter but I need to be able to do a step by step execution of the program and being able to see the values of variables, the stack...all that in a web interface.
The idea is to help C beginners by showing them the step by step execution of the program. We are using GWT to build the interface so if something exists in Java we should be able to use it.
I can modify it to suit my needs but if I can avoid to write the parser / abstract-syntax tree walker / stack manipulation... that would be great.
Edit :
To be clear I don't want to simulate the complete C because some programs can be really tricky.
By step I mean a basic operation such as : expression evaluation, affectation, function call.
The C I want to simulate will contains : variables, for, while, functions, arrays, pointers, maths functions. No goto, string functions, ctypes.h, setjmp.h... (at least for now).
Here is a prototype : http://www.di.ens.fr/~fevrier/war/simu.html
In this example we have manually converted the C code to a javascript representation but it's limited (expressions such as a == 2 || a = 1
are not handled) and is limited to programs manually converted.
We have a our disposal a C compiler on a remote server so we can check if the code is correct (and doesn't have any undefined behavior). The parsing / AST construction can also be done remotely (so any language) but the AST walking needs to be in javascript in order to run on the client side.
tcc
which was written in C but is run in the form of x86 opcodes. TCC compiles C programs to x86 executables pretty much directly and that x86 code is again run by the stack mentioned above. Good luck using that from Javascript! – JujubeC
is a very small language. Your requirement asking for "not the whole of C" doesn't really cut you any slack. I don't think this is trivially doable. – MarneyC
proper is about 2 dozen keywords, a few operators and a few types. You'll need these even for the simplest of programs and even the most complex ones will need exactly these. Saying that you don't need "string.h" doesn't make the problem any simpler. – Marney