LambdaJS is small, tested, reduction semantics for JavaScript. It was proposal by Brown PLT group in 2010. Read their paper.
This repo reproduces the translation ("desguar") between JavaScript and LambdaJS using Ocaml.
- JavaScript is processed by Flow Parser first to generate JS AST.
- The translation is working on the JS AST, and the output is LambdaJS AST. That is the core part of this repo.
- A small utility is written to serialize the LambdaJS AST to S-expression.
- LambdaJS S-expression interpreter is from original LambdaJS codebase. The desugar result can be executed and tested directly by it.
Please install opam
, OCaml (>= 4.07)
and Racket(>= 7.2)
first. You can find guide for installing opam
here.
Then a few third-party libraries are necessary:
opam install merlin user-setup menhir utop ppx_deriving ounit2 qcheck
opam pin add flow_parser https://github.com/facebook/flow.git
Finally,
dune build # build the repo
dune runtest # and run all unit tests!
You can translate JS in example/qsort.js and run generated lambdaJS directly by:
cat ./examples/qsort.js | dune exec ./src/translate.exe | ./interp/interp-shell.ss
dune exec
completes pipeline step 1-3 and interp-shell
finishes pipeline step 4. The output is written to stdout
.
Below lists supported feature. All of them are in example
directory. You can replace the js file in above command and run it directly.
- Arithmetic: arithmetic.js
- If statement: condition.js
- Without alternative: simple_cond.js
- While statement: while.js
- Array: array.js
- Array index: array_index.js
- Dictionary: dict.js
- Delete ops: dict_delete.js
- Field manipulation: arithmetic_dict.js
- Function: argument_passing.js
- Function argument: argument_changing.js
- High-order function: high_order.js
- Support prototype chain, and other interesting syntax.
- Added black-box tests to check output of interpreter, rather than S-expression.
- Brown University proposed S5, an extension for LambdaJS with ES5 support. Maybe we can learn something from it.