[antlr-interest] Why is the parser trying to match the wrong rule?

Loring Craymer lgcraymer at yahoo.com
Wed Jul 18 08:36:04 PDT 2007


I suspect that NUMBER hides DIGIT and that '2' is read
as a NUMBER and so does not parse as part of a day.

Try
NUMBER : DIGIT (DIGIT)+ ;
and replacing occurrences of NUMBER with
number : DIGIT | NUMBER ;

--Loring

--- Jonas Tampier <jonas+antlr at pmhost.de> wrote:

> Hello,
> I just recently discovered ANTLR for my own use,
> that's why I still have 
> a severe knowledge deficit regarding the grammar
> definition.
> 
> I want to use ANTLR to parse calendar data I recieve
> into a tree to 
> handle it more easily.
> However it seems, that my grammar does not fit the
> data structure, yet. 
> Sadly I don't understand why.
> 
> I run into the problem, that daysOfWeek does just
> match the first day. 
> So the parser ends with the errormessage:
> line 4:8 mismatched input '2' expecting 'Exceptions'
> which indicates, that it tries to match the
> exceptions rule instead of 
> the day rule.
> 
> I'd be glad to get a hint pointing me into the right
> direction.
> 
> Jonas Tampier
> 
> 
> This is the grammar:
> 
>
/*------------------------------------------------------------------
>  * PARSER RULES
> 
>
*------------------------------------------------------------------*/
>  
>  calendarData
>      :    PARLEFT DIGIT PIPE 'CalendarData' PARLEFT
> PARRIGHT PARLEFT 
> daysOfWeek view? exceptions? PARRIGHT ;
> 
>  daysOfWeek
>      :    PARLEFT DIGIT PIPE 'DaysOfWeek' PARLEFT
> PARRIGHT PARLEFT day+ 
> PARRIGHT;
>  day     :    PARLEFT DIGIT PIPE DAYNUMBER PARLEFT
> PARRIGHT PARLEFT 
> shift* PARRIGHT ;
>  shift     :    PARLEFT DIGIT PIPE DIGIT PARLEFT 's'
> '|' TIME '|' 'f' 
> '|' TIME PARRIGHT PARLEFT PARRIGHT PARRIGHT;
>  
>  view     :    PARLEFT DIGIT PIPE 'VIEW' PARLEFT
> 'ShowTotal' PIPE YESNO 
> PARRIGHT PARLEFT PARRIGHT PARRIGHT;
>  
>  exceptions
>      :    PARLEFT DIGIT PIPE 'Exceptions' PARLEFT
> PARRIGHT PARLEFT 
> exceptionDay PARRIGHT;
>  exceptionDay
>      :    PARLEFT DIGIT PIPE NUMBER PARLEFT 'd' PIPE
> NUMBER PARRIGHT 
> PARLEFT shift* PARRIGHT;
> 
> 
>
/*------------------------------------------------------------------
>  * LEXER RULES
> 
>
*------------------------------------------------------------------*/
> DAYNUMBER : '1'..'7';
> PARLEFT :     '(';
> PARRIGHT:    ')';
> PIPE : '||';
> DIGIT    : '0'..'9' ;
> 
> YESNO    :    'Y' | 'N';
> 
> TIME     : '0'..'2' DIGIT ':' '0'..'5' DIGIT;
> 
> NUMBER    : (DIGIT)+ ;
> 
> WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+
>     { $channel = 
> HIDDEN; } ;
> 
> 
> And this is the data:
> 
> (0||CalendarData()(
>   (0||DaysOfWeek()(
>     (0||1()())
>     (0||2()(
>       (0||0(s|07:00|f|19:00)())))
>     (0||3()(
>       (0||0(s|07:00|f|19:00)())))
>     (0||4()(
>       (0||0(s|07:00|f|19:00)())))
>     (0||5()(
>       (0||0(s|07:00|f|19:00)())))
>     (0||6()(
>       (0||0(s|07:00|f|19:00)())))
>     (0||7()())))
>   (0||VIEW(ShowTotal|N)())
>   (0||Exceptions()(
>     (0||0(d|38345)())
>     (0||1(d|38352)())))))
> 



       
____________________________________________________________________________________
Got a little couch potato? 
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz 


More information about the antlr-interest mailing list