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

Pete Siemsen siemsen at UCAR.EDU
Sun Oct 7 09:11:16 PDT 2007


Austin,

> You don't provide a definition of StringConstant. Does it perchance  
> start with a SINGLEQUOTE instead of a DOUBLEQUOTE?

When I cut/pasted the grammar in the message that started this  
thread, I somehow missed two rules at the end.  Sorry about that.   
Appended is a newer example grammar that addresses that problem and  
the ones you mention below.

> Also, your examples include backslashes, but your StringCharacter  
> definition implicitly excludes them.

Perhaps the appended grammar is better about this.

> Finally, your StringCharacter definition is just dumb. If you want  
> to exclude certain characters, use the ~ (tilde) exclusion  
> character. Don't code around them. It took me a trip to an ascii  
> table to figure out what you were doing. Had you asked earlier this  
> afternoon, when my laptop wasn't in wifi range of the internet, I  
> wouldn't have had one available.

Quite right.  The appended grammar is better.

But it still exhibited the problem with "mismatched input 'include'  
expecting set null".  Another person answered this thread, explaining  
that I have to explicitly specify whitespace in lexer rules like the  
PragmaInclude rule.  I did so and fixed the problem.

Thank you very much!

-- Pete


grammar cimmof2java;

tokens {
     BACKSLASH       = '\\'              ;
     DOUBLEQUOTE     = '"'               ;
     INCLUDE         = 'include'         ;
     LOCALE          = 'locale'          ;
     LPAREN          = '('               ;
     PRAGMA          = '#pragma'         ;
     RPAREN          = ')'               ;
     SINGLEQUOTE     = '\''              ;
}


mofSpecification
	: (mofProduction)+
	;

mofProduction
	: compilerDirective
     ;

compilerDirective
	: PRAGMA (PragmaInclude | pragmaLocale)
	;

PragmaInclude
	: INCLUDE WhiteSpace LPAREN f=StringConstant RPAREN
	;

pragmaLocale
	: LOCALE WhiteSpace LPAREN StringConstant RPAREN
	;

WhiteSpace
	: ( ' ' | '\t' | '\n' | '\r')+ {$channel=HIDDEN;}
	;

StringConstant
     : DOUBLEQUOTE ( EscapeSequence | StupidEscapeSequence | ~( '\\'  
| '"' ) )* DOUBLEQUOTE
	;

fragment
EscapeSequence
	: BACKSLASH ( 'b' | 't' | 'n' | 'f' | 'r' | DOUBLEQUOTE |  
SINGLEQUOTE | BACKSLASH)
	| HexEscape
	;

fragment
StupidEscapeSequence
	: BACKSLASH ( 'C' | 'P' )
	;

fragment
HexEscape
	: BACKSLASH 'x' HexDigit
	| BACKSLASH 'x' HexDigit HexDigit
	| BACKSLASH 'x' HexDigit HexDigit HexDigit
	| BACKSLASH 'x' HexDigit HexDigit HexDigit HexDigit
	;
	
fragment
HexDigit
	: ('0'..'9'|'a'..'f'|'A'..'F') ;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071007/4a2bcae8/attachment-0001.html 


More information about the antlr-interest mailing list