This method transforms the start state computed by
#computeStartState to the special start state used by a
precedence DFA for a particular precedence value. The transformation
process applies the following changes to the start state's configuration
set.
- Evaluate the precedence predicates for each configuration using
SemanticContext#evalPrecedence.
- When
ATNConfig#isPrecedenceFilterSuppressed is
false,
remove all configurations which predict an alternative greater than 1,
for which another configuration that predicts alternative 1 is in the
same ATN state with the same prediction context. This transformation is
valid for the following reasons:
- The closure block cannot contain any epsilon transitions which bypass
the body of the closure, so all states reachable via alternative 1 are
part of the precedence alternatives of the transformed left-recursive
rule.
- The "primary" portion of a left recursive rule cannot contain an
epsilon transition, so the only way an alternative other than 1 can exist
in a state that is also reachable via alternative 1 is by nesting calls
to the left-recursive rule, with the outer calls not being at the
preferred precedence level. The
ATNConfig#isPrecedenceFilterSuppressed property marks ATN
configurations which do not meet this condition, and therefore are not
eligible for elimination during the filtering process.
The prediction context must be considered by this filter to address
situations like the following.
grammar TA;
prog: statement* EOF;
statement: letterA | statement letterA 'b' ;
letterA: 'a';
If the above grammar, the ATN state immediately before the token
reference
'a' in
letterA is reachable from the left edge
of both the primary and closure blocks of the left-recursive rule
statement. The prediction context associated with each of these
configurations distinguishes between them, and prevents the alternative
which stepped out to
prog (and then back in to
statementfrom being eliminated by the filter.