Antlr3.Tool.Grammar.GetLookaheadDFA C# (CSharp) Method

GetLookaheadDFA() public method

public GetLookaheadDFA ( int decision ) : Antlr3.Analysis.DFA
decision int
return Antlr3.Analysis.DFA
        public virtual DFA GetLookaheadDFA( int decision )
        {
            Decision d = GetDecision( decision );
            if ( d == null )
            {
                return null;
            }
            return d.dfa;
        }

Usage Example

        //throws Exception
        protected void checkDecision( Grammar g,
                                     int decision,
                                     string expecting,
                                     int[] expectingUnreachableAlts )
        {
            Antlr3.AntlrTool tool = new Antlr3.AntlrTool();
            // mimic actions of org.antlr.Tool first time for grammar g
            if ( g.CodeGenerator == null )
            {
                CodeGenerator generator = new CodeGenerator( tool, g, "Java" );
                g.CodeGenerator = generator;
                g.BuildNFA();
                g.CreateLookaheadDFAs( false );
            }

            DFA dfa = g.GetLookaheadDFA( decision );
            Assert.IsNotNull(dfa, "unknown decision #" + decision);
            FASerializer serializer = new FASerializer( g );
            string result = serializer.Serialize( dfa.StartState );
            //System.out.print(result);
            var nonDetAlts = dfa.UnreachableAlts;
            //System.out.println("alts w/o predict state="+nonDetAlts);

            // first make sure nondeterministic alts are as expected
            if ( expectingUnreachableAlts == null )
            {
                if ( nonDetAlts != null && nonDetAlts.Count != 0 )
                {
                    Console.Error.WriteLine( "nondeterministic alts (should be empty): " + ( (IList)nonDetAlts ).ToElementString() );
                }
                Assert.AreEqual(0, nonDetAlts != null ? nonDetAlts.Count : 0, "unreachable alts mismatch");
            }
            else
            {
                for ( int i = 0; i < expectingUnreachableAlts.Length; i++ )
                {
                    Assert.IsTrue(nonDetAlts != null ? nonDetAlts.Contains(expectingUnreachableAlts[i]) : false, "unreachable alts mismatch");
                }
            }
            Assert.AreEqual( expecting, result );
        }
All Usage Examples Of Antlr3.Tool.Grammar::GetLookaheadDFA
Grammar