[antlr-interest] N00b question

Anders Karlsson anders at globe-trotter.us
Wed Aug 20 19:04:35 PDT 2008


Hi,

I have this simple little grammar where I would like to parse an ini-file that format ID="somevalue" on each line
but I get an error when running in ANTLRworks saying MismatchedTokenException using a simple test line A1="AAA". If I below, change VALUE to be IDENTIFIER again it seems to work 

e.g. 

expr
	:	(IDENTIFIER '=' '"' IDENTIFIER '"' ) 
	;

So if somebody could explain why the below grammar doesn't work it would help me understand better.

TIA
Anders.

grammar inifile;

options
{
language=C;
}

prog : stat+;

stat
	:	expr NEWLINE
	;

expr
	:	(IDENTIFIER '=' '"' VALUE '"' ) 
	;

// lex rules

IDENTIFIER
    :	LETTER (LETTER|DIGIT)*
    ;

VALUE
    :	(LETTER|DIGIT)*
    ;
	
fragment
LETTER
    :	'$'
    |	'A'..'Z'
    |	'a'..'z'
    |	'_'
    ; 	

fragment
DIGIT
:'0'..'9';

NEWLINE 
	:	'\r'? | '\n' | { $channel=HIDDEN; } 
	;


More information about the antlr-interest mailing list