public TreeToNFAConverter( Grammar g, NFA nfa, NFAFactory factory, ITreeNodeStream input )
     : this(input)
 {
     this.grammar = g;
     this.nfa = nfa;
     this.factory = factory;
 }
Esempio n. 2
0
        /** Define all the rule begin/end NFAStates to solve forward reference
         *  issues.  Critical for composite grammars too.
         *  This is normally called on all root/delegates manually and then
         *  buildNFA() is called afterwards because the NFA construction needs
         *  to see rule start/stop states from potentially every grammar. Has
         *  to be have these created a priori.  Testing routines will often
         *  just call buildNFA(), which forces a call to this method if not
         *  done already. Works ONLY for single noncomposite grammars.
         */
        public virtual void CreateRuleStartAndStopNFAStates()
        {
            //[email protected]("### createRuleStartAndStopNFAStates "+getGrammarTypeString()+" grammar "+name+" NFAs");
            if ( nfa != null )
            {
                return;
            }
            nfa = new NFA( this );
            factory = new NFAFactory( nfa );

            foreach ( Rule r in Rules )
            {
                string ruleName = r.Name;
                NFAState ruleBeginState = factory.NewState();
                ruleBeginState.Description = "rule " + ruleName + " start";
                ruleBeginState.enclosingRule = r;
                r.StartState = ruleBeginState;
                NFAState ruleEndState = factory.NewState();
                ruleEndState.Description = "rule " + ruleName + " end";
                ruleEndState.IsAcceptState = true;
                ruleEndState.enclosingRule = r;
                r.StopState = ruleEndState;
            }
        }