C. Scott Ananian, based on a grammar by Douglas Crockford
This demo is heavily modified from Douglas Crockford's original Top Down Operator Precedence JavaScript grammar demo, which is described in chapter 9 of the book Beautiful Code.
This page contains a tokenizer, parser, bytecode compiler, and bytecode interpreter for Simplified JavaScript, all of which are written in Simplified JavaScript. This page compiles all these pieces to bytecode and then runs them in the interpreter. The interpreted version of the bytecode compiler is given a simple addition statement to compile.
This page loads five main JavaScript files:
tokenize.js | This file installs the tokenize function which produces an array of simple tokens from a string. |
parse.js | This file installs the parse function. |
bytecode_table.js | This file installs the bytecode_table object which
wraps the short list of bytecode instructions used by the compiler and
interpreter. |
bcompile.js | This file installs the bcompile function. This
compiles a parse tree into a list of bytecode-compiled functions. |
binterp.js | This file installs the binterp object which
contains the bytecode interpreter. It piggybacks on the
meta-level's object system, but otherwise tries hard not to
let meta-level definitions leak into the interpreted state.
All primitive objects and library functions are reimplemented
inside the interpreter, for example. |