[antlr-interest] "Missing" Tokens Do Not Cause Errors
Kevin Carroll
kcarroll at signmgmt.com
Fri May 28 12:49:22 PDT 2010
Here are a couple of simple rules extracted from a combined grammar I have:
RETURNS : ('R'|'r')'eturns' { $text = "RETURNS"; } ;
returnsStatement
: RETURNS ':' type ';' -> ^(RETURNS type)
;
(type's definition is, I think, irrelevant. It matches the typical things - int, double, etc.).
Note that the rule uses the rewrite syntax and omits the ':' and ';' tokens in the AST.
I am observing that my parser accepts inputs even when these tokens are missing.
For example, the line: "returns double" is accepted (note, no ':' or ';'). In stepping through the parse, the Match() method calls that should match the ':' and ';' return '<missing ':'>' and '<missing ';'>', respectively, yet do not fail. I understand that a feature of ANTLR is that missing tokens are sometimes automatically inserted to allow the parse to proceed, but shouldn't the erroneous line(s) be reported?
Is this behavior correct and/or expected? If not, does anyone have any clues as to what might be going wrong?
Thanks,
Kevin Carroll
More information about the antlr-interest
mailing list