I'm trying to parse a file with antlr 4, I can't get why integer of more than one digit are not parsified (line 79:44 no viable alternative at input '17').
This is the entier grammar http://pastebin.com/rxktvUBi
Here is the definition of int
fragment DIGIT : [0-9] ;
integer : DIGIT+ ;
which doesn't work at all. This version
integer : ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9')+ ;
works only for 1 digit integers.
This is an example of line not parsified
struct p_77_bound_17_or: ((bound(MEK)<=17) | (bound(MEKPP)<=17))
The problem is in
simple_expression:
(integer)+
Note that if I use identifier
ID:
('a'..'z'|'A'..'Z'|'0'..'9'|'_')+;
identifier: ID;
instead of integer
simple_expression:
identifier
that works.
Why? Any Idea?
Your integer
rule is a parser rule, not a lexer rule. The '0'
, '1'
, etc. literals it references are implicitly turned into lexer rules which match a single digit each. You should make the following lexer rule instead:
INTEGER : '0'..'9'+;
Or in ANTLR 4, simply this:
INTEGER : [0-9]+;