[antlr-interest] MismatchedTokenException in loop
Arne Schröder
arne.schroeder at gmail.com
Mon Oct 12 02:47:25 PDT 2009
Hi,
I am trying to parse the following input:
[
MSG1:
MSG2: cmd1 cmd2
MSG3: cmd3
]
which means on MSG1 and MSG2 commands cmd1 and cmd2 should be executed, on
MSG3 the command cmd3 should be executed.
I tried the following grammar:
grammar msg_test;
msg_list: LSQUARE msg_impl* RSQUARE ;
msg_impl: (ID COLON)+ stmnt* ;
stmnt : ID | INT ;
LSQUARE : '[' ;
RSQUARE : ']' ;
COLON : ':' ;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
INT : '0'..'9'+;
WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;};
But this results in the following warning:
[10:59:35] warning(200): msg_test.g:3:20: Decision can match input such as
"ID" using multiple alternatives: 1, 2
When I run the parser I get a MismatchedTokenException on cmd2.
When changing msg_impl by removing + to
msg_impl: (ID COLON) stmnt* ;
the parser works fine (no warnings, the input is being parsed), but the
"connection" between MSG1 and MSG2 is lost and I cannot create an AST-Node
containing all messages that should be handled the same way.
It seems as if the COLON is not used in the stmnt* lookahead part to break
out of the loop. Why? Can I force it somehow?
Thanks for help and best regards
Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091012/5610f61e/attachment.html
More information about the antlr-interest
mailing list