Antlr4.Analysis.LeftRecursionDetector.Check C# (CSharp) Method

Check() public method

public Check ( Rule enclosingRule, ATNState s, ISet visitedStates ) : bool
enclosingRule Antlr4.Tool.Rule
s Antlr4.Runtime.Atn.ATNState
visitedStates ISet
return bool
        public virtual bool Check(Rule enclosingRule, ATNState s, ISet<ATNState> visitedStates)
        {
            if (s is RuleStopState)
                return true;
            if (visitedStates.Contains(s))
                return false;
            visitedStates.Add(s);

            //System.out.println("visit "+s);
            int n = s.NumberOfTransitions;
            bool stateReachesStopState = false;
            for (int i = 0; i < n; i++)
            {
                Transition t = s.Transition(i);
                if (t is RuleTransition)
                {
                    RuleTransition rt = (RuleTransition)t;
                    Rule r = g.GetRule(rt.ruleIndex);
                    if (rulesVisitedPerRuleCheck.Contains((RuleStartState)t.target))
                    {
                        AddRulesToCycle(enclosingRule, r);
                    }
                    else
                    {
                        // must visit if not already visited; mark target, pop when done
                        rulesVisitedPerRuleCheck.Add((RuleStartState)t.target);
                        // send new visitedStates set per rule invocation
                        bool nullable = Check(r, t.target, new HashSet<ATNState>());
                        // we're back from visiting that rule
                        rulesVisitedPerRuleCheck.Remove((RuleStartState)t.target);
                        if (nullable)
                        {
                            stateReachesStopState |= Check(enclosingRule, rt.followState, visitedStates);
                        }
                    }
                }
                else if (t.IsEpsilon)
                {
                    stateReachesStopState |= Check(enclosingRule, t.target, visitedStates);
                }
                // else ignore non-epsilon transitions
            }
            return stateReachesStopState;
        }

Same methods

LeftRecursionDetector::Check ( ) : void

Usage Example

Example #1
0
        public virtual void Process()
        {
            // LEFT-RECURSION CHECK
            LeftRecursionDetector lr = new LeftRecursionDetector(g, g.atn);
            lr.Check();
            if (lr.listOfRecursiveCycles.Count > 0)
                return; // bail out

            if (g.IsLexer())
            {
                ProcessLexer();
            }
            else
            {
                // BUILD DFA FOR EACH DECISION
                ProcessParser();
            }
        }
All Usage Examples Of Antlr4.Analysis.LeftRecursionDetector::Check