[antlr-interest] problem with parser
Kevin J. Cummings
cummings at kjchome.homeip.net
Wed Sep 28 16:55:32 PDT 2011
On 09/28/2011 02:50 PM, jame vaalet wrote:
> hi,
> below is my tree grammar:
>
> tokens
> {
> COMMA=',';
> LPAREN='(';
> RPAREN=')';
>
> }
>
> start : (NUMBER^ COMMA NUMBER)|WORD^;
>
> WORD : ~(WHITESPACE|LPAREN|RPAREN)+ ;
> WHITESPACE : ('\t'|' '|'\r'|'\n'|'\u000C');
> NUMBER : DIGIT+;
> fragment DIGIT : '0'..'9' ;
>
>
> when my input is 1,2 which one is it gonna match ? WORD or (NUMBER^ COMMA
> NUMBER)
The former is a lexer rule, the latter a parser rule. The lexer will
match as much as possible before the parser even runs. If NUMBER COMMA
NUMBER needs to be parsed, then you need to re-define your WORD rule so
that it doesn't match it.
> I want this to be matched to latter by antlr i matching it with former..
> what am i missing here..
--
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://www.xlinuxcounter.net/)
More information about the antlr-interest
mailing list