C interpreter written in javascript C interpreter written in javascript c c

C interpreter written in javascript


There's a C grammar available for antlr that you can use to generate a C parser in Java, and possibly JavaScript too.


There is em-scripten which converts LLVM languages to JS a little hacking on it and you may be able to produce a C interperter.


felixh's JSCPP project provides a C++ interpreter in Javascript, though with some limitations.

https://github.com/felixhao28/JSCPP

So an example program might look like this:

var JSCPP = require('JSCPP');var launcher = JSCPP.launcher;var code = 'int main(){int a;cin>>a;cout<<a;return 0;}';var input = '4321';var exitcode = launcher.run(code, input);console.info('program exited with code ' + exitcode);

As of March 2015 this is under active development, so while it's usable there are still areas where it may continue to expand. Check the documentation for limitations. It looks like you can use it as a straight C interpreter with limited library support for now with no further issues.