The MOO Code Unparser: /lib/unparser

The unparser has the job of converting a verb abstract syntax tree back into its original source form. A seemingly simple task is actually non-trivial, due to the complications of operator precedences and parentheses.

The unparser can beautify code (or not) by inserting (or not inserting) indentation into the source to show the outline of execution blocks. It can also fully-parenthesize all expressions, or only parenthesize the expressions that are required due to operator precedence.

The unparser's interface is:

    string *program;
    mixed *ast;
    int full_parens, do_indent;

    program = UNPARSER->main(ast, full_parens, do_indent);
The unparser returns an array of strings containing the source program.

No intentional errors are ever generated by the parser. Unfortunately it has happened that the source code returned from the unparser is not semantically correct, due to parenthesization problems. As far as it is known, all of these problems have been corrected.


rob@ccs.neu.edu