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

Loring Craymer lgcraymer at yahoo.com
Fri Dec 8 17:10:19 PST 2006


--- "r. clayton" <rvclayton at acm.org> wrote:

   
> There is no such thing as a branch-local declaration
> in antlr 2.
> 
>   I disagree:
> 
>     $ cat t.a
>     class test 
>     extends Parser;
> 
>     a: { char c; } A { c = 'A'; }
>      |             B { c = 'B'; }
>      ;
> 
>     $ java antlr.Tool t.a
>     ANTLR Parser Generator   Version 2.7.6
> (20060528)   1989-2005
> 
>     $ javac test.java
>     test.java:58: cannot find symbol
>     symbol  : variable c
>     location: class test
> 				  c = 'B';
> 				    ^
>     1 error
> 
>     $ 
> 
>   The code for each branch is enclosed in a separate
> scope, so anything
>   declared in one branch is not accessible outside
> the branch; hence
>   branch-local declarations.
> 

Try changing your grammar slightly:
    class test 
    extends Parser;

    a: { char c; } (A)=> A { c = 'A'; }
     |             B { c = 'B'; }
     ;
 
and you will see what Monty means:  it will have
problems with c = 'A';

--Loring

> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the antlr-interest mailing list