Antlr3.Tool.ErrorManager.LeftRecursionCycles C# (CSharp) Method

LeftRecursionCycles() public static method

public static LeftRecursionCycles ( System.Collections.ICollection cycles ) : void
cycles System.Collections.ICollection
return void
        public static void LeftRecursionCycles( ICollection cycles )
        {
            GetErrorState().errors++;
            Message msg = new LeftRecursionCyclesMessage( cycles );
            GetErrorState().errorMsgIDs.Add( msg.msgID );
            GetErrorListener().Error( msg );
        }

Usage Example

Beispiel #1
0
        /** Check all rules for infinite left recursion before analysis. Return list
         *  of troublesome rule cycles.  This method has two side-effects: it notifies
         *  the error manager that we have problems and it sets the list of
         *  recursive rules that we should ignore during analysis.
         */
        public virtual IList <HashSet <Rule> > CheckAllRulesForLeftRecursion()
        {
            grammar.BuildNFA(); // make sure we have NFAs
            grammar.leftRecursiveRules = new HashSet <Rule>();
            List <HashSet <Rule> > listOfRecursiveCycles = new List <HashSet <Rule> >();

            for (int i = 0; i < grammar.composite.RuleIndexToRuleList.Count; i++)
            {
                Rule r = grammar.composite.RuleIndexToRuleList[i];
                if (r != null)
                {
                    visitedDuringRecursionCheck = new HashSet <Rule>();
                    visitedDuringRecursionCheck.Add(r);
                    HashSet <object> visitedStates = new HashSet <object>();
                    TraceStatesLookingForLeftRecursion(r.StartState,
                                                       visitedStates,
                                                       listOfRecursiveCycles);
                }
            }
            if (listOfRecursiveCycles.Count > 0)
            {
                ErrorManager.LeftRecursionCycles(listOfRecursiveCycles);
            }
            return(listOfRecursiveCycles);
        }