[antlr-interest] How to interpret an IF with antlr 3.0
ugol
ugo.landini at gmail.com
Sat May 5 14:26:16 PDT 2007
> Hi all,
> I am back with the same question. 3 months ago I rolled back to
> javacc, which I know marginally better, but now I really want to move
> to antlr. Unfortunately, I can't figure out how to delay the
> processing of a node... (if this is the correct solution)
>
> If you don't want to read all this old thread, the question is:
>
> - How to translate this antlr v2 in antlr v3?
>
> ^(IF condition x:.) // x is NOT evaluated, merely captured
> { if ($condition.value) { stat(x); }
Ok, I have found a way, thanks to the c-- interpreter (here if someone
needs it http://www.antlr.org/share/1178224532340/cminus.zip).
It works pretty well, but isn't the old v2 syntax more concise?
^(IF condition .)
{
if ($condition.value) {
CommonTree ifStmt = (CommonTree)$stat.start.getChild(1);
stream.push(stream.getNodeIndex(ifStmt));
stat();
stream.pop();
}
}
More information about the antlr-interest
mailing list