[antlr-interest] what means "mismatched input 'xxx' expecting set null"

Gavin Lambert antlr at mirality.co.nz
Sat Oct 6 22:57:13 PDT 2007


At 17:51 7/10/2007, Pete Siemsen wrote:
>PragmaInclude
>: INCLUDE LPAREN f=StringConstant RPAREN
>;
[...]
>The above grammar produces the error.  What's wrong?

Since PragmaInclude is a lexer rule, it won't discard whitespace 
(or to be more specific, it won't generate whitespace tokens and 
then either skip them or push them onto a hidden channel).  So 
anywhere that whitespace may occur within a lexer rule you will 
need to explicitly specify it.

>Perhaps it's relevant that if I change the "P" on "PragmaLocale" 
>to "p", I get this error instead:
>
>line 1:8 no viable alternative at input 'include'
>line 2:8 no viable alternative at input 'include'
>line 3:8 no viable alternative at input 'include'

It's hard to say for this one -- you've specified "StringConstant" 
in your rule but haven't actually given a definition for it in the 
grammar you posted.  If that's actually what you've got (or if 
StringConstant is a fragment rule), then that's your 
problem.  Parser rules can only (usefully) refer to non-fragment 
lexer rules that the lexer will actually generate :)  (ANTLR won't 
complain about typos, irritatingly -- it assumes you are referring 
to another token it simply hasn't seen the definition for yet -- 
even if it never does.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071007/6c8eeb4f/attachment.html 


More information about the antlr-interest mailing list