1
votes

I am new to this section, i want to identify two digit integers in following range [1-3][0-9]. i wrote it as

goal        : firstD secondD WS firstD secondD;     
firstD      : '1'|'2'|'3';
secondD     : '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' ;
WS          :   (' '|'\t'|'\n'|'\r')+ {skip();} ;

but this gives the MismatchedTokenException. is there anything wrong in my grammer ?

2

2 Answers

1
votes

You get a MismatchedTokenException because you used the WS rule in your goal rule. But this WS rule is being skipped from the lexer. Either remove it from your goal rule, or remove the {skip();} part from WS.

0
votes

Try this for your white spaces :

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

and remove WS from goal definition.