[antlr-interest] (no subject)
lin q
linq936 at gmail.com
Tue Oct 2 10:24:58 PDT 2012
Hi,
I like to parse some simple name/value pair data file in the format of
"name=value" at each line, here is an example:
race=asia
age=10
name=uart
gender=m
I have the following grammar snippet:
/*-------------------------------------------------------------------------------------------
parser rules
-------------------------------------------------------------------------------------------*/
all_rec
: common_param
EOF
;
common_param
: ( 'gender=' VAL )
|
( 'race=' VAL )
|
( 'name=' VAL )
|
( 'age=' VAL )
New_Line+
;
/*-------------------------------------------------------------------------------------------
lexer rules
-------------------------------------------------------------------------------------------*/
VAL : ('a'..'z' | 'A'..'Z' | '0'..'9' | '_' | '.' )+ ;
WS : ('\t' | ' ')+ ;
New_Line : ('\r' | '\n')+ ;
But when I run it, I get the following error:
test.in(1) : error 1 : Unexpected token, at offset 8
near [Index: 2 (Start: 309691209-Stop: 309691209) ='
', type<4> Line: 1 LinePos:8]
: syntax error...
The content of test.in is
race=asia
age=10
name=uart
gender=m
Do you see what exactly is the problem?
More information about the antlr-interest
mailing list