previous | top | next

Example #2: AST-based interpreter


ast_interpreter.cpp (3K)

Printf is the exception that "proves" the rule: It is difficult to gain significant advantage from a quick and easy/lone-developer bytecode interpreter.

More often, you can use the Composite design pattern to represent the abstract syntax tree (avoid writing a parser, just connect up the tree that you would want the parser to output).
SIGPLAN / interpreter design pattern