History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ANTLR-24
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Terence Parr
Reporter: Terence Parr
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ANTLR v3

generates unknown n_1 variable

Created: 06/Nov/06 06:29 PM   Updated: 20/Apr/07 01:32 PM
Component/s: ANTLR Core
Affects Version/s: 3.0
Fix Version/s: 3.0b8


 Description  « Hide
With the following grammar

grammar a;
options {output=AST;}
tokens {PARMS;}

modulo
 : 'modulo' ID ('(' parms+ ')')? -> ^('modulo' ID ^(PARMS parms+)?)
 ;
parms : '#'|ID;
ID : ('a'..'z' | 'A'..'Z')*;
WS : (' ' | '\t' | '\n' | '\r')+ {channel=99;} ;
The compiler result is

a.java:150: cannot find symbol
symbol : variable n_1
location: class a
                if ( n_1 > 1 ) throw new RuntimeException(" list has >
1 elements");
                     ^
a.java :151: cannot find symbol
symbol : variable n_1
location: class a
                if ( n_1==1 ) {
                     ^

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Terence Parr - 16/Dec/06 06:39 PM
A better example is

grammar t;
options {output=AST;}
                    
tokens { VARDEF; }

a : 'int' ID? -> VARDEF? ;

Terence Parr - 20/Apr/07 01:32 PM
Fixed by making (...)? blocks test all refs nested within for content.