[antlr-interest] help - Parser problem

virg g 06virg at gmail.com
Sun Nov 30 21:56:52 PST 2008


Hi,
 I have set of commands which I need to parse. This is my sample grammar
file.
It is able to parse if command is

"TESTCMD CNT=2 VAL=TYPE:test123"

If the command is
TESTCMD CNT=2 VAL=TYPE:CNT

It returs error "EarlyExitException" , if i change lexer rules i get
Mismatchtokenexception. But command is never successful. I have figured out
that If the literal contains any of these keywords CNT, VAL, TYPE, RTEST
parsing fails, that means it igonres these tokens while parsing by parser
eventhough these tokens(eg CNT) is/are created by Lexer.
How can i resolve this kind of problems. I cannot avoid having these tokens
in my command as the literal can be any of form. Really i am stuck here.

Also similarly i have set of different commands. If the parser finds any
unknown command it returns error and breaks the parsing. But i want to
continue to parse other commands. How to resume the parsing even if there
are any unknown commands found?

grammar testcmds;

tokens{
RTEST='TESTCMD';
}

commands:    command+;
//command:TESTCMD CNT= number 'VAL' '=' 'TYPE:' literal ;
command: RTEST count_value type_value;

count_value: 'CNT' '=' NUMBER;

type_value:    'VAL' '=' 'TYPE' ':' value;

value: literal;
literal    : (NUMBER|ALPHA|STRING)+
    ;

NUMBER    :    (DIGIT)+;

ALPHA    : ('a'..'z'|'A'..'Z')+
    ;
STRING: ('!' | '#'..'/' | '>'..'@' | '['..'`' | '{'..'~')+;

fragment DIGIT :    '0'..'9';

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

Any help is highly appreciated. Thanks in advance.

- Virg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081201/b5e8d7c1/attachment.html 


More information about the antlr-interest mailing list