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

CreateLookaheadDFAs() public method

public CreateLookaheadDFAs ( bool wackTempStructures ) : void
wackTempStructures bool
return void
        public virtual void CreateLookaheadDFAs( bool wackTempStructures )
        {
            if ( nfa == null )
            {
                BuildNFA();
            }

            // CHECK FOR LEFT RECURSION; Make sure we can actually do analysis
            CheckAllRulesForLeftRecursion();

            /*
            // was there a severe problem while sniffing the grammar?
            if ( ErrorManager.doNotAttemptAnalysis() ) {
                return;
            }
            */

            DateTime start = DateTime.Now;

            //[email protected]("### create DFAs");
            int numDecisions = NumberOfDecisions;
            if ( NFAToDFAConverter.SINGLE_THREADED_NFA_CONVERSION )
            {
                for ( int decision = 1; decision <= numDecisions; decision++ )
                {
                    NFAState decisionStartState = GetDecisionNFAStartState( decision );
                    if ( leftRecursiveRules.Contains( decisionStartState.enclosingRule ) )
                    {
                        // don't bother to process decisions within left recursive rules.
                        if ( composite.WatchNFAConversion )
                        {
                            Console.Out.WriteLine( "ignoring decision " + decision +
                                               " within left-recursive rule " + decisionStartState.enclosingRule.Name );
                        }
                        continue;
                    }
                    if ( !externalAnalysisAbort && decisionStartState.NumberOfTransitions > 1 )
                    {
                        Rule r = decisionStartState.enclosingRule;
                        if ( r.IsSynPred && !synPredNamesUsedInDFA.Contains( r.Name ) )
                        {
                            continue;
                        }
                        DFA dfa = null;
                        // if k=* or k=1, try LL(1)
                        if ( GetUserMaxLookahead( decision ) == 0 ||
                             GetUserMaxLookahead( decision ) == 1 )
                        {
                            dfa = CreateLL_1_LookaheadDFA( decision );
                        }
                        if ( dfa == null )
                        {
                            if ( composite.WatchNFAConversion )
                            {
                                Console.Out.WriteLine( "decision " + decision +
                                                   " not suitable for LL(1)-optimized DFA analysis" );
                            }
                            dfa = CreateLookaheadDFA( decision, wackTempStructures );
                        }
                        if ( dfa.StartState == null )
                        {
                            // something went wrong; wipe out DFA
                            SetLookaheadDFA( decision, null );
                        }
                        if ( Tool.internalOption_PrintDFA )
                        {
                            Console.Out.WriteLine( "DFA d=" + decision );
                            FASerializer serializer = new FASerializer( nfa.Grammar );
                            string result = serializer.Serialize( dfa.StartState );
                            Console.Out.WriteLine( result );
                        }
                    }
                }
            }
            else
            {
                ErrorManager.Info( "two-threaded DFA conversion" );
                // create a barrier expecting n DFA and this main creation thread
                Barrier barrier = new Barrier( 3 );
                // assume 2 CPU for now
                int midpoint = numDecisions / 2;
                NFAConversionThread t1 =
                    new NFAConversionThread( this, barrier, 1, midpoint );
                new System.Threading.Thread( t1.Run ).Start();
                //new Thread( t1 ).start();
                if ( midpoint == ( numDecisions / 2 ) )
                {
                    midpoint++;
                }
                NFAConversionThread t2 =
                    new NFAConversionThread( this, barrier, midpoint, numDecisions );
                new System.Threading.Thread( t2.Run ).Start();
                //new Thread( t2 ).start();
                // wait for these two threads to finish
                try
                {
                    barrier.WaitForRelease();
                }
                //catch ( InterruptedException e )
                //{
                //    ErrorManager.internalError( "what the hell? DFA interruptus", e );
                //}
                catch
                {
                    throw new System.NotImplementedException();
                }
            }

            DateTime stop = DateTime.Now;
            DFACreationWallClockTimeInMS = stop - start;

            // indicate that we've finished building DFA (even if #decisions==0)
            allDecisionDFACreated = true;
        }

Same methods

Grammar::CreateLookaheadDFAs ( ) : void

Usage Example

 public void TestSimpleRangeVersusChar()
 {
     Grammar g = new Grammar(
         "lexer grammar t;\n" +
         "A : 'a'..'z' '@' | 'k' '$' ;" );
     g.CreateLookaheadDFAs();
     string expecting =
         ".s0-'k'->.s1" + NewLine +
         ".s0-{'a'..'j', 'l'..'z'}->:s2=>1" + NewLine +
         ".s1-'$'->:s3=>2" + NewLine +
         ".s1-'@'->:s2=>1" + NewLine;
     checkDecision( g, 1, expecting, null );
 }
All Usage Examples Of Antlr3.Tool.Grammar::CreateLookaheadDFAs
Grammar