Consider the following simplified grammar:
ID : ('a'..'z') ('a'..'z')*;
TYPE : 'int' '[' ']' |
'boolean' |
'int';
Now if I write boolean as input, it can be parsed as ID or as TYPE. I want it to be parsed as TYPE – how?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Put
TYPEbeforeID:ANTLR’s lexer rules work like this:
Because of these rules,
"boolean"is tokenized asTYPE, while"booleans"would be tokenized asID11
"booleans"is not tokenized as two tokens:TYPE("boolean") and anID("s"))