0
votes

Does the order of choices among lexer subrules matter in ANTLR4? For example, is there any difference between the following rules?

STRING: '"' ('\\"' | .)*? '"';
STRING: '"' (. | '\\"')*? '"';
1

1 Answers

1
votes

The first lexical rule can match the whole of such an input as: "abc\"def". the second will match only part of it, that is, "abc\", and then report error for the rest character sequence.

Antlr generated lexer matches the subrule first which defined first. I have tested them on Antlr 4.