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

r. clayton rvclayton at acm.org
Fri Dec 8 16:22:05 PST 2006


Below your code block is an action, not a declaration.  

  I get your point, but I don't think it explains much.  The example has an
  action that contains a declaration.

All actions are wrapped in if(guessing) so that syntactic predicates work.
This is not a bug.

  Maybe, maybe not.  I would argue that it is erroneous behavior, but I
  wouldn't argue too strenuously because it looks like a fix will be
  complicated.

  Whatever it's called, however, it's unpleasant and unexpected behavior when
  it happens, particularly in the spooky, break-something-unrelated-over-there
  way shown in the original example.
  
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.



More information about the antlr-interest mailing list