antlr4 - ANTLR v4 grammar fails to parse due to mismatched EOF -
follows simple grammar antlr v4. grammar when walked produces error message **line 1:14 mismatched input '' expecting dimensionname*
for trivial input such "sdarsfd integer" (without quotation marks).
so has mention f similar errors , bug perhaps filed in 4.3 timeframe. have been using antlr 4.5.
any help/pointer/solution?
/** simple parser dimension declaration */ grammar simple; definition : dim; dim : dimensionname datatype; dimensionname : letter (letter)*; // greedy datatype: 'integer' | 'decimal'; letter : [a-za-z]; digit : [0-9]; ws: [ \t\n\r]+ -> skip;
you have switch 2 lexer rules datatype
, dimensionname
... datatype: 'integer' | 'decimal'; dimensionname : letter (letter)*; // greedy ...
as dimensionname
matches every chars, 'integer' typed dimensionname
instead of datatype
. "sdarsfd integer", lexer produces 2 dimensionname
token, dim
rule cannot matched. switching 2 lexer rules, lexer produces dimensionname
token , datatype
token match dim
rule.
also, can define letter
, digit
fragment:
fragment letter : [a-za-z]; fragment digit : [0-9];
unless want them matched independent token (in grammar, "a" typed letter
).
Comments
Post a Comment