[antlr-interest] Changing the order of statements

Federico Bellucci federico.bellucci at gmail.com
Thu Dec 16 07:17:28 PST 2010


I am working on a JavaScript to JavaScript compiler that modifies the
functions.
I am using the complete EcmaScript grammar [1] by Patrick Hulsmeijer.

I wrote a Symbol Table builder and a complete code generator based on the
Terence Parr sample in [2] and and the Hulsmeijer's tree walker.

I need to exchange the order of statements inside functions.
In particular I have to move the functions declarations on the top of the
function body (or the global scope).

Example:

stament_1;
function foo () {
  statement_a;
  function baz() {}
}

becomes:

function foo () {
  function baz() {}
  statement_a;
}
stament_1;

I tried to modify the generator, but I had problem of recursion because
functions can contain other functions. So I'm wondering about the chance to
directly modify the tree before generating the code.

What would you advise me to do?

Thank you,
Federico


[1] http://research.xebic.com/
[2] http://pragprog.com/titles/tpdsl/language-implementation-patterns


More information about the antlr-interest mailing list