[antlr-interest] Faster expression parsing for ANTLR

Zenzike zenzike at gmail.com
Thu Dec 18 01:18:38 PST 2008


Thanks for the reply.

> Instead of using a rule parameter in the predicate, assign the rule parameter to a scope variable. The 'scope' is never out of scope unless you found a path to a > rule where it was not created.

I thought about that, but I wasn't sure it would work -- wouldn't the
scope be shared between the recursive calls to e[]?

e[int p]
   :   (primary->primary)
       (   {prec[input.LA(1)]>=p}?=>     bop r=e[nextp(p)] -> ^(bop $e $r)
       |   {postprec[input.LA(1)]>=p}?=> suffix[$e.tree]   -> {$suffix.tree}
       )*
   ;

If the parameter p were scoped, rather than passed, then we forget the
call-tree that gets us to our current position don't we?
My understanding might be wrong -- I thought scoped in the grammar
became static variables in the target language, is that true?

zenzike


More information about the antlr-interest mailing list