[antlr-interest] Why is the parser trying to match the wrong rule?
Jonas Tampier
jonas+antlr at pmhost.de
Wed Jul 18 07:50:23 PDT 2007
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)())))))
More information about the antlr-interest
mailing list