Peter Boughton wrote: >> (It's not the use of string literals vs token rules that is significant >> here; just whether arrow is a lexer or parser rule. This seems to be >> one of the most common mistakes made by people new to ANTLR.) > > Just to clarify, you're saying that a parser rule will always take > precedence over a lexer rule, if both are possible?
The model is that the lexer produces a sequence of tokens that are input to the parser. So lexer rules don't have precedence relative to parser rules; they are applied at different stages. To use ANTLR effectively, you need to have a clear idea of what should count as a token for your grammar, since that determines the boundary between the lexer and parser. For most languages, this is constrained by the fact that tokens can have ignored whitespace between them, but not within them. > Does the order of the alternation matter? > (i.e. "RARROW | COLON" vs "COLON | RARROW") No, not in this case. (It can matter, but normally only if you ignore an ambiguity warning.) -- David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
signature.asc
Description: OpenPGP digital signature
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
