[antlr-interest] "Missing" Tokens Do Not Cause Errors
Jim Idle
jimi at temporal-wave.com
Fri May 28 13:31:59 PDT 2010
Sounds like you are using ANTLRWorks? They are reported, but they don't thrown exceptions.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Kevin Carroll
> Sent: Friday, May 28, 2010 12:49 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] "Missing" Tokens Do Not Cause Errors
>
> 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
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
More information about the antlr-interest
mailing list