help on Parser problem
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   06_virg
Posted On:   Friday, November 28, 2008 08:27 AM

I have set of commands which I need to parse. This is my sample grammar file It is able to parse if the command is "TESTCMD CNT=2 VAL=TYPE:test123" If the command is TESTCMD CNT=2 VAL=TYPE:CNT It returns 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 ignores these tokens while parsing by parser even though 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 co   More>>

I have set of commands which I need to parse. This is my sample grammar file

It is able to parse if the command is

"TESTCMD CNT=2 VAL=TYPE:test123"


If the command is

TESTCMD CNT=2 VAL=TYPE:CNT


It returns 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 ignores these tokens while parsing

by parser even though 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 : ( ' ' | ' ' | '
' | '
'| 'u000C' )+ { $channel = HIDDEN; };




Any help is highly appreciated. Thanks in advance.

- Virg    <<Less
About | Sitemap | Contact