[antlr-interest] n00b Question

Anders Karlsson anders at globe-trotter.us
Thu Aug 21 18:41:34 PDT 2008


Another n00b question :)

Given this grammar ( to handle ini-files with statements like A=1 and B="adds sadsa"):

prog : stat+;

stat
	:	expr (NEWLINE | EOF)
	;

expr
	:	IDENTIFIER '='^ VALUE 
	;

// lex rules

IDENTIFIER
    :	LETTER (LETTER|DIGIT)*
    ;

// here seems to be a problem

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

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

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

fragment
WS	: ' '|'\t' { $channel=HIDDEN; } ;

(removed some actions for clarity)

I think there seems to be some problem with the VALUE rule
I wish is to accept both A=1 and A="1" in an ini-file
When VALUE contains the 2nd subrule ANTLRWorks doesn't
work in the interpreter, if I comment that rule it works fine but
then I am restricted to values having quotation marks

I don't quite understand why it doesn't work.

Any ideas?
TIA
Anders.


More information about the antlr-interest mailing list