Hi,
I have the following recognition problem and do not know how to solve it correctly with ANTLR 3.3. Please look at the following sketch grammar.
grammar Test;
test : accessA | accessB;
accessA : '%' 'M' ('W' | 'D') INTEGER;
accessB : 'Instr#' ID;
INTEGER : ('0'..'9')+;
ID : ('A' .. 'Z' | 'a' .. 'z') ('A' .. 'Z' | 'a' .. 'z' | INTEGER | '_')*;
The goal is, if an '%' is recognized in an input like '%MD1', the following 'M' and ''D' should be recognized separate. Because 'M' should trigger an action and 'D' also. But in a sentence like 'Instr#MD1' the 'MD1' should be recognized as ID token.
Currently, the lexer tokenizes '%MD1' as '%' ID not '%' 'M' 'D' INTEGER.
I understand that the lexer acts greedy and tries to consume as much input as possible. Is there a way to help the Lexer/Parser with predicates?
Many thanks!