[antlr-interest] How to execute a tree multiple times?

Simon Manschitz simon.werbung at gmx.de
Tue Dec 14 03:46:34 PST 2010


Hallo,

if have to unroll a fore loop inside my AST.

For example if have a tree like: (for (= a (: 1 4)) (= output (+ output a))

where a = 1:4 is the condition and (= output (+ output a) is the body of the for loop.

This tree should be create an output like:

a = 1;
output = output + a;
a = 2;
output = output + a;
a = 3;
output = output + a;
a = 4;
output = output + a;

I have other rules that execute the expressions inside the for loop. This is my rule of the for loop:

for_command:
  ^(FOR assign_expression prog*);

So i want to determine the length of the matrix of assign_expression and execute (prog*) length times. Is it possible to execute the {} Code of a tree several times?

Something like:
code=(prog*){
    code.tree.execute();
}

Bye, Simon.

-- 
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit 
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl


More information about the antlr-interest mailing list