| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| pack-priv static class | PredictionMode.
A Map that uses just the state and the stack context as the key. |
| Modifier and Type | Field and Description |
|---|---|
| public static final PredictionMode | LL
The LL(*) prediction mode. |
| public static final PredictionMode | LL_EXACT_AMBIG_DETECTION
The LL(*) prediction mode with exact ambiguity detection. |
| public static final PredictionMode | SLL
The SLL(*) prediction mode. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static boolean | allConfigsInRuleStopStates(ATNConfigSet
the configuration set to test configs)Checks if all configurations in |
| public static boolean | allSubsetsConflict(Collection<BitSet>
a collection of alternative subsets altsets)Determines if every alternative subset in |
| public static boolean | Returns: true if every member of altsets is equal to the
others, otherwise falsea collection of alternative subsets altsets)Determines if every alternative subset in |
| public static BitSet | Returns: the set of represented alternatives inaltsetsa collection of alternative subsets altsets)Gets the complete set of represented alternatives for a collection of alternative subsets. |
| public static BitSet | |
| public static Collection | getConflictingAltSubsets(ATNConfigSet configs)
This function gets the conflicting alt subsets from a configuration set. |
| public static int | |
| public static Map | |
| public static int | getUniqueAlt(Collection<BitSet>
a collection of alternative subsets altsets)Returns the unique alternative predicted by all alternative subsets in
|
| public static boolean | hasConfigInRuleStopState(ATNConfigSet
the configuration set to test configs)Checks if any configuration in |
| public static boolean | hasConflictingAltSet(Collection<BitSet>
a collection of alternative subsets altsets)Determines if any single alternative subset in |
| public static boolean | hasNonConflictingAltSet(Collection<BitSet>
a collection of alternative subsets altsets)Determines if any single alternative subset in |
| public static boolean | hasSLLConflictTerminatingPrediction(PredictionMode mode, ATNConfigSet configs)
Computes the SLL prediction termination condition. |
| public static boolean | |
| public static int | |
| public static PredictionMode | |
| public static PredictionMode[] |
| LL | back to summary |
|---|---|
| public static final PredictionMode LL The LL(*) prediction mode. This prediction mode allows the current parser context to be used for resolving SLL conflicts that occur during prediction. This is the fastest prediction mode that guarantees correct parse results for all combinations of grammars with syntactically correct inputs. When using this prediction mode, the parser will make correct decisions for all syntactically-correct grammar and input combinations. However, in cases where the grammar is truly ambiguous this prediction mode might not report a precise answer for exactly which alternatives are ambiguous. This prediction mode does not provide any guarantees for prediction behavior for syntactically-incorrect inputs. | |
| LL_EXACT_AMBIG_DETECTION | back to summary |
|---|---|
| public static final PredictionMode LL_EXACT_AMBIG_DETECTION The LL(*) prediction mode with exact ambiguity detection. In addition to
the correctness guarantees provided by the This prediction mode may be used for diagnosing ambiguities during grammar development. Due to the performance overhead of calculating sets of ambiguous alternatives, this prediction mode should be avoided when the exact results are not necessary. This prediction mode does not provide any guarantees for prediction behavior for syntactically-incorrect inputs. | |
| SLL | back to summary |
|---|---|
| public static final PredictionMode SLL The SLL(*) prediction mode. This prediction mode ignores the current parser context when making predictions. This is the fastest prediction mode, and provides correct results for many grammars. This prediction mode is more powerful than the prediction mode provided by ANTLR 3, but may result in syntax errors for grammar and input combinations which are not SLL.
When using this prediction mode, the parser will either return a correct
parse tree (i.e. the same parse tree that would be returned with the
This prediction mode does not provide any guarantees for prediction behavior for syntactically-incorrect inputs. | |
| PredictionMode | back to summary |
|---|---|
| private PredictionMode() | |
| allConfigsInRuleStopStates | back to summary |
|---|---|
| public static boolean allConfigsInRuleStopStates(ATNConfigSet configs) Checks if all configurations in
| |
| allSubsetsConflict | back to summary |
|---|---|
| public static boolean allSubsetsConflict(Collection<BitSet> altsets) Determines if every alternative subset in
| |
| allSubsetsEqual | back to summary |
|---|---|
| public static boolean allSubsetsEqual(Collection<BitSet> altsets) Determines if every alternative subset in
| |
| getAlts | back to summary |
|---|---|
| public static BitSet getAlts(Collection<BitSet> altsets) Gets the complete set of represented alternatives for a collection of
alternative subsets. This method returns the union of each
| |
| getAlts | back to summary |
|---|---|
| public static BitSet getAlts(ATNConfigSet configs) Get union of all alts from configs.
| |
| getConflictingAltSubsets | back to summary |
|---|---|
| public static Collection This function gets the conflicting alt subsets from a configuration set.
For each configuration
map[c] U= c.
| |
| getSingleViableAlt | back to summary |
|---|---|
| public static int getSingleViableAlt(Collection<BitSet> altsets) | |
| getStateToAltMap | back to summary |
|---|---|
| public static Map Get a map from state to alt subset from a configuration set. For each
configuration map[c. | |
| getUniqueAlt | back to summary |
|---|---|
| public static int getUniqueAlt(Collection<BitSet> altsets) Returns the unique alternative predicted by all alternative subsets in
| |
| hasConfigInRuleStopState | back to summary |
|---|---|
| public static boolean hasConfigInRuleStopState(ATNConfigSet configs) Checks if any configuration in
| |
| hasConflictingAltSet | back to summary |
|---|---|
| public static boolean hasConflictingAltSet(Collection<BitSet> altsets) Determines if any single alternative subset in
| |
| hasNonConflictingAltSet | back to summary |
|---|---|
| public static boolean hasNonConflictingAltSet(Collection<BitSet> altsets) Determines if any single alternative subset in
| |
| hasSLLConflictTerminatingPrediction | back to summary |
|---|---|
| public static boolean hasSLLConflictTerminatingPrediction(PredictionMode mode, ATNConfigSet configs) Computes the SLL prediction termination condition. This method computes the SLL prediction termination condition for both of the following cases.
COMBINED SLL+LL PARSING When LL-fallback is enabled upon SLL conflict, correct predictions are ensured regardless of how the termination condition is computed by this method. Due to the substantially higher cost of LL prediction, the prediction should only fall back to LL when the additional lookahead cannot lead to a unique SLL prediction. Assuming combined SLL+LL parsing, an SLL configuration set with only
conflicting subsets should fall back to full LL, even if the
configuration sets don't resolve to the same alternative (e.g.
Here's the prediction termination rule them: SLL (for SLL+LL parsing) stops when it sees only conflicting configuration subsets. In contrast, full LL keeps going when there is uncertainty. HEURISTIC As a heuristic, we stop prediction when we see any conflicting subset unless we see a state that only has one alternative associated with it. The single-alt-state thing lets prediction continue upon rules like (otherwise, it would admit defeat too soon):
When the ATN simulation reaches the state before It also let's us continue for this rule:
After matching input A, we reach the stop state for rule A, state 1. State 8 is the state right before B. Clearly alternatives 1 and 2 conflict and no amount of further lookahead will separate the two. However, alternative 3 will be able to continue and so we do not stop working on this state. In the previous example, we're concerned with states associated with the conflicting alternatives. Here alt 3 is not associated with the conflicting configs, but since we can continue looking for input reasonably, don't declare the state done. PURE SLL PARSING To handle pure SLL parsing, all we have to do is make sure that we combine stack contexts for configurations that differ only by semantic predicate. From there, we can do the usual SLL termination heuristic. PREDICATES IN SLL+LL PARSING SLL decisions don't evaluate predicates until after they reach DFA stop states because they need to create the DFA cache that works in all semantic situations. In contrast, full LL evaluates predicates collected during start state computation so it can ignore predicates thereafter. This means that SLL termination detection can totally ignore semantic predicates. Implementation-wise,
Before testing these configurations against others, we have to merge
If the configuration set has predicates (as indicated by
| |
| hasStateAssociatedWithOneAlt | back to summary |
|---|---|
| public static boolean hasStateAssociatedWithOneAlt(ATNConfigSet configs) | |
| resolvesToJustOneViableAlt | back to summary |
|---|---|
| public static int resolvesToJustOneViableAlt(Collection<BitSet> altsets) Full LL prediction termination. Can we stop looking ahead during ATN simulation or is there some uncertainty as to which alternative we will ultimately pick, after consuming more input? Even if there are partial conflicts, we might know that everything is going to resolve to the same minimum alternative. That means we can stop since no more lookahead will change that fact. On the other hand, there might be multiple conflicts that resolve to different minimums. That means we need more look ahead to decide which of those alternatives we should predict. The basic idea is to split the set of configurations Reduce these configuration subsets to the set of possible alternatives. You can compute the alternative subsets in one pass as follows:
Or in pseudo-code, for each configuration
map[c] U= c.
The values in If Reduce the subsets to singletons by choosing a minimum of each subset. If the union of these alternative subsets is a singleton, then no amount of more lookahead will help us. We will always pick that alternative. If, however, there is more than one alternative, then we are uncertain which alternative to predict and must continue looking for resolution. We may or may not discover an ambiguity in the future, even if there are no conflicting subsets this round. The biggest sin is to terminate early because it means we've made a decision but were uncertain as to the eventual outcome. We haven't used enough lookahead. On the other hand, announcing a conflict too late is no big deal; you will still have the conflict. It's just inefficient. It might even look until the end of file. No special consideration for semantic predicates is required because predicates are evaluated on-the-fly for full LL prediction, ensuring that no configuration contains a semantic context during the termination check. CONFLICTING CONFIGS Two configurations For simplicity, I'm doing a equality check between CONTINUE/STOP RULE Continue if union of resolved alternative sets from non-conflicting and conflicting alternative subsets has more than one alternative. We are uncertain about which alternative to predict. The complete set of alternatives, CASES
EXACT AMBIGUITY DETECTION If all states report the same conflicting set of alternatives, then we know we have the exact ambiguity set.
In other words, we continue examining lookahead until all | |
| valueOf | back to summary |
|---|---|
| public static PredictionMode valueOf(String name) | |
| values | back to summary |
|---|---|
| public static PredictionMode[] values() | |
| Modifier and Type | Field and Description |
|---|---|
| public static final PredictionMode. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(ATNConfig
The first object to compare. a, ATNConfig The second object to compare. b)Implements org. |
| public int | hashCode(ATNConfig
The object. o)Implements org. ATNState#stateNumber
and ATNConfig#context.
|
| INSTANCE | back to summary |
|---|---|
| public static final PredictionMode. | |
| AltAndContextConfigEqualityComparator | back to summary |
|---|---|
| private AltAndContextConfigEqualityComparator() | |
| equals | back to summary |
|---|---|
| public boolean equals(ATNConfig a, ATNConfig b) Implements org. Doc from org. This method tests if two objects are equal. | |
| hashCode | back to summary |
|---|---|
| public int hashCode(ATNConfig o) Implements org. The hash code is only a function of the
| |
| Access | Constructor and Description |
|---|---|
| public |
| AltAndContextMap | back to summary |
|---|---|
| public AltAndContextMap() | |