[antlr-interest] Lexer question
John Howard
john.howard9 at btinternet.com
Mon Apr 9 03:24:54 PDT 2007
With Gavin Lambert input (Many thanks Gavin) I have moved my grammar
forward, but still have an issue with one aspect. I'm trying to parse
tokens such as '53xx' '6xxx' '3334' and the following simple grammar
works if I have token SHAPE defined, but if I use shapeDist I get a
mis-match of against ID for the first 'x'. 333x parses OK, but 33xx
doesn't. I can's use SHAPE, because that causes other problems with the
grammar. Is there any way I can get shapeDist to work?
Thanks,
John
// This works
dist
: '^' SHAPE
;
ID : ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')+;
SHAPE :(DIGIT (DIGIT|'*'|'x'|'X') (DIGIT|'*'|'x'|'X')
(DIGIT|'*'|'x'|'X'));
DIGIT : ('0'..'9') ;
WS : (' '|'\r'|'\t'|'\n')+{$channel=HIDDEN;} ;
// This fails
dist
: '^' shapeDist
;
shapeDist
: (DIGIT (DIGIT|'*'|'x'|'X') (DIGIT|'*'|'x'|'X') (DIGIT|'*'|'x'|'X'))
;
ID : ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')+;
DIGIT : ('0'..'9') ;
WS : (' '|'\r'|'\t'|'\n')+{$channel=HIDDEN;} ;
More information about the antlr-interest
mailing list