I'm new to ANTLR, so this is probably a simple question.
I defined a simple grammar, which should include arithmetic expressions with numbers and identifiers (lines starting with a letter and continuing with one or more letters or numbers).
The grammar is as follows:
grammar while;
@lexer::header {
package ConFreeG;
}
@header {
package ConFreeG;
import ConFreeG.IR.*;
}
@parser::members {
}
arith:
term
| '(' arith ( '-' | '+' | '*' ) arith ')'
;
term returns [AExpr a]:
NUM
{
int n = Integer.parseInt($NUM.text);
a = new Num(n);
}
| IDENT
{
a = new Var($IDENT.text);
}
;
fragment LOWER : ('a'..'z');
fragment UPPER : ('A'..'Z');
fragment NONNULL : ('1'..'9');
fragment NUMBER : ('0' | NONNULL);
IDENT : ( LOWER | UPPER ) ( LOWER | UPPER | NUMBER )*;
NUM : '0' | NONNULL NUMBER*;
fragment NEWLINE:'\r'? '\n';
WHITESPACE : ( ' ' | '\t' | NEWLINE )+ { $channel=HIDDEN; };
I am using ANTLR v3 with the ANTLR IDE Eclipse plugin. When I parse an expression (8 + a45)with an interpreter, only part of the parse tree is generated:

Why is the second term (a45) not analyzed? The same thing happens if both conditions are numbers.
Thank,
Martin Vibo
source
share