[antlr-interest] Syntactic predicates vs branch-local declarations.

r. clayton rvclayton at acm.org
Thu Dec 7 18:32:51 PST 2006


Antlr 2.7.7 is generating bad code for grammars using both syntactic predicates
and branch-local declarations, as in

  a: { int v1, v2; } A  v1 = b  v2 = b;

  c: (d) => d | e;

Part of the code generated is

  if ( inputState.guessing==0 ) {
    int v1, v2;
    }
  match(A);
  v1=b();
  v2=b();

which doesn't compile because v1 and v2 can't escape their scope.  The fix is
to make the branch-local declarations rule local:

  a { int v1, v2; } : A  v1 = b  v2 = b;








More information about the antlr-interest mailing list