[antlr-interest] Syntactic predicates vs branch-local declarations.
Monty Zukowski
monty at codetransform.com
Fri Dec 8 09:47:51 PST 2006
Below your code block is an action, not a declaration. All actions
are wrapped in if(guessing) so that syntactic predicates work. This
is not a bug. There is no such thing as a branch-local declaration in
antlr 2.
a: { int v1, v2; } A v1 = b v2 = b;
Monty
On 07 Dec 2006 21:32:51 -0500, r. clayton <rvclayton at acm.org> wrote:
> 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