[antlr-interest] what means "mismatched input 'xxx' expecting set null"
Pete Siemsen
siemsen at UCAR.EDU
Sat Oct 6 21:51:56 PDT 2007
I'm trying to implement include file processing with ANTLR 3.0.1. I
stole liberally from the
ANTLR Wiki page that describes it (http://www.antlr.org/wiki/pages/
viewpage.action?pageId=557057).
Now my grammar doesn't recognize my test input file, which contains just
#pragma include ("System\CIM_DiagnosticResult.mof")
#pragma include ("Event\CIM_Indication.mof")
#pragma include ("Core\CIM_ManagedElement.mof")
When I run it, I get
line 1:8 mismatched input 'include' expecting set null
line 2:8 mismatched input 'include' expecting set null
line 3:8 mismatched input 'include' expecting set null
Finally, here's the grammar. I stripped it down to just the relevant
stuff:
grammar cimmof2java;
tokens {
BACKSLASH = '\\' ;
DOUBLEQUOTE = '"' ;
INCLUDE = 'include' ;
LOCALE = 'locale' ;
LPAREN = '(' ;
PRAGMA = '#pragma' ;
RPAREN = ')' ;
SINGLEQUOTE = '\'' ;
}
mofSpecification
: (mofProduction)+
;
mofProduction
: compilerDirective
;
compilerDirective
: PRAGMA (PragmaInclude | PragmaLocale)
;
PragmaInclude
: INCLUDE LPAREN f=StringConstant RPAREN
;
PragmaLocale
: LOCALE LPAREN StringConstant RPAREN
;
WhiteSpace
: ( ' ' | '\t' | '\n' | '\r')+ {$channel=HIDDEN;}
;
fragment
StringCharacter
: ' '..'!' | '#'..'[' | ']'..'~'
;
The above grammar produces the error. What's wrong?
Note that the PragmaInclude rule used to be a parser rule, with a
lowercase "p". Include processing works in the lexer, so I changed
the "p" to a "P". ANTLR accepts it and produces compileable Java,
but when I run it I get the errors.
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'
-- Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071006/b23524f0/attachment.html
More information about the antlr-interest
mailing list