Package org.antlr.v4.analysis
Class LeftRecursionDetector
java.lang.Object
org.antlr.v4.analysis.LeftRecursionDetector
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Grammar
Holds a list of cycles (sets of rule names).(package private) Set
<RuleStartState> Which rule start states have we visited while looking for a single left-recursion check? -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addRulesToCycle
(Rule enclosingRule, Rule targetRule) enclosingRule calls targetRule.void
check()
boolean
From state s, look for any transition to a rule that is currently being traced.
-
Field Details
-
g
Grammar g -
atn
-
listOfRecursiveCycles
Holds a list of cycles (sets of rule names). -
rulesVisitedPerRuleCheck
Set<RuleStartState> rulesVisitedPerRuleCheckWhich rule start states have we visited while looking for a single left-recursion check?
-
-
Constructor Details
-
LeftRecursionDetector
-
-
Method Details
-
check
public void check() -
check
From state s, look for any transition to a rule that is currently being traced. When tracing r, visitedPerRuleCheck has r initially. If you reach a rule stop state, return but notify the invoking rule that the called rule is nullable. This implies that invoking rule must look at follow transition for that invoking state. The visitedStates tracks visited states within a single rule so we can avoid epsilon-loop-induced infinite recursion here. Keep filling the cycles in listOfRecursiveCycles and also, as a side-effect, set leftRecursiveRules. -
addRulesToCycle
enclosingRule calls targetRule. Find the cycle containing the target and add the caller. Find the cycle containing the caller and add the target. If no cycles contain either, then create a new cycle.
-