A humble ocaml-to-javascript transpiler I made to study for my Functional Programming Course at McGill
Ocaml Lex and Grammar rules are described in ocaml.jison
, however the actual parser is in ocaml.js
, automatically generated by jison
First, install dependencies with:
npm install
A live interpreter-style transpiler can now be run with:
node interpreter.js
Type any valid ocaml expression, ending with ;;
and the 'interpreter' will print the javascript equivalent.
Simple variable and function assignment examples
$ node interpreter.js
# let x = 1;;
var x = 1
# let y = 2.0;;
var y = 2.0
# let add a b = a + b;;
var add = function(a, b) {
return a + b;
}
# add x y ;;
add(x, y)
Note after any changes are made to the grammer in ocaml.jison
the parser must be re-compiled.
First, install jison with:
npm install jison -g
Now you can generate the parser with:
jison ocaml.jison
this command must always be re-run afer any changes are made to ocaml.jison
interpreter.js
can now be re-run with the new grammar rules.
Copyright 2017 Gabriel Downs
This project is free software, licensed under the GNU GPL.
Please see included LICENSE
file, or http://www.gnu.org/licenses/ for more details.