[antlr-interest] How can I avoid "mismatched input" error?

Gabriel Petrovay gabriel.petrovay at 28msec.com
Tue Mar 24 00:59:41 PDT 2009


Hi all,

I have the following grammar file:

//========================================
grammar k;
options {
output=AST;
}

rule : KEYWORD1 (KEYWORD2 enc=Name)? ';' ;

KEYWORD1 : 'keyword1';
KEYWORD2 : 'keyword2';

Name : Letter* ;
fragment Letter : 'a'..'z' | 'A'..'Z' ;

S            :    ('\t' | ' ' | '\n' | '\r')+  { $channel = HIDDEN; } ;
//========================================


The following text is not a valid one.

INPUT:
=====
keyword1 keyword2 keyword1 ;

OUTPUT:
=======
line 1:18 mismatched input 'keyword1' expecting Name
<mismatched token: [@4,18:25='keyword1',<4>,1:18], resync=keyword1 keyword2
keyword1 ;>


How can I make a parser to recognize this input? I want to be able to allow
the keywords in the places where any char combination is allowed. How can I
make this?

Regards,
Gabriel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090324/f57ea376/attachment.html 


More information about the antlr-interest mailing list