Posted By:
06_virg
Posted On:
Monday, October 6, 2008 12:42 AM
grammar test1; tokens{ TEST='TEST'; COUNT = 'COUNT'; VAL='VAL'; TYPE='TYPE'; } commands: command; //command:'TEST' COUNT= INT 'VAL' '=' 'TYPE:' ID ; command: TEST cnt_value type_value; cnt_value: COUNT '=' INT; type_value: VAL '=' TYPE ':' value; value: ID; INT : (DIGIT)+; //ID: ('a'..'z'|'A'..'Z'|'0'..'9'|'!' | '#'..'/' | ':'..'@' | '['..'`' | '{'..'~')+; ID: ('a'..'z'|'A'..'Z'|'0'..'9'|'!' | '#'..'/' | '>'..'@' | '['..'`' | '{'..'~')+; fragment DIGIT : '0'..'9'; WHITESPACE : ( ' ' | ' ' | ' ' | ' '| 'u000C' )+ { $channel = HIDDEN; };
More>>
grammar test1;
tokens{
TEST='TEST';
COUNT = 'COUNT';
VAL='VAL';
TYPE='TYPE';
}
commands: command;
//command:'TEST' COUNT= INT 'VAL' '=' 'TYPE:' ID ;
command: TEST cnt_value type_value;
cnt_value: COUNT '=' INT;
type_value: VAL '=' TYPE ':' value;
value: ID;
INT : (DIGIT)+;
//ID: ('a'..'z'|'A'..'Z'|'0'..'9'|'!' | '#'..'/' | ':'..'@' | '['..'`' | '{'..'~')+;
ID: ('a'..'z'|'A'..'Z'|'0'..'9'|'!' | '#'..'/' | '>'..'@' | '['..'`' | '{'..'~')+;
fragment DIGIT : '0'..'9';
WHITESPACE : ( ' ' | ' ' | '
' | '
'| 'u000C' )+ { $channel = HIDDEN; };
This is my sample code. I am checking the syntax of a command. The command is
'TEST' COUNT= CNT 'VAL' '=' TYPE ':' ID ;
where CNT is integer and ID is a string which is a combination of all characters + special characters+number.
if the ID contains a "":"" and ""="" it gives the value up to the first occurance of "":"" or ""="".
eg: TEST COUNT=3 VAL=TYPE:HREF:http://test.com. It returns value of ID as TYPE:HREF. If i include "":"" and ""="" in the Lexer RULE for ID
I get MismatchedTokenException. How to get the complete string for ID as TYPE:HREF:http://test.com.
What could be the problem.What changes I have to make. I am stuck here. Any help is highly appreciated. Thanks in advance.
Virg
<<Less