Yes, ANTLR's lexer operates using the following rules:
- try to create a token with the most amount of characters
- if there are 2 or more rules that match the same characters, let the one defined first "win"
Because the input "reserved" can be matched by both the Reserved and Identifier rule, the one defined first (Reserved) gets precedence.
It sometimes happens that keywords kan also be used as identifiers. This is often done by introducing a identifier parser rule that matches an Identifier token or some reserved keywords:
identifier : Reserved | Identifier; Reserved : 'reserved'; Identifier : [a-z]+;
and then use identifier in other parser rules instead of directly using Identifier.
EDIT
After rereading your question: yes, parser rule alternatives are tried from left to right (top to bottom). In the rule p: p : a | b | c;, first a is tried, then b and lastly c.
Note that in your example prog: Reserved | Identifier;, there is no ambiguity since the input "reserved" will never become an Identifier token (the first part of my answer).
[a-b]should be[a-z]Reservedoccurs beforeIdentifiersoReservedalways matches. Always print out the token types of the tokens when degugging your grammar.