Esempio n. 1
0
        public virtual void CreateStateTables( CodeGenerator generator )
        {
            //[email protected]("createTables:\n"+this);
            this._generator = generator;
            Description = NFADecisionStartState.Description;
            Description = generator.Target.GetTargetStringLiteralFromString( Description );

            // create all the tables
            //special = new List<int>( this.NumberOfStates ); // Vector<short>
            //special.setSize( this.NumberOfStates );
            _special = Enumerable.Repeat( EmptyValue, NumberOfStates ).ToArray();
            _specialStates = new List<DFAState>();
            _specialStateSTs = new List<StringTemplate>();
            //accept = new List<int>( this.NumberOfStates ); // Vector<int>
            //accept.setSize( this.NumberOfStates );
            _accept = Enumerable.Repeat( EmptyValue, NumberOfStates ).ToArray();
            //eot = new List<int>( this.NumberOfStates ); // Vector<int>
            //eot.setSize( this.NumberOfStates );
            _eot = Enumerable.Repeat( EmptyValue, NumberOfStates ).ToArray();
            //eof = new List<int>( this.NumberOfStates ); // Vector<int>
            //eof.setSize( this.NumberOfStates );
            _eof = Enumerable.Repeat( EmptyValue, NumberOfStates ).ToArray();
            //min = new List<int>( this.NumberOfStates ); // Vector<int>
            //min.setSize( this.NumberOfStates );
            _min = Enumerable.Repeat( EmptyValue, NumberOfStates ).ToArray();
            //max = new List<int>( this.NumberOfStates ); // Vector<int>
            //max.setSize( this.NumberOfStates );
            _max = Enumerable.Repeat( EmptyValue, NumberOfStates ).ToArray();
            _transition = new int[NumberOfStates][]; // Vector<Vector<int>>
            //transition.setSize( this.NumberOfStates );
            _transitionEdgeTables = new List<int?>( this.NumberOfStates ); // Vector<Vector<int>>
            _transitionEdgeTables.Resize( this.NumberOfStates );

            // for each state in the DFA, fill relevant tables.
            IEnumerable<DFAState> it = null;
            if ( UserMaxLookahead > 0 )
            {
                it = _states;
            }
            else
            {
                it = UniqueStates.Values;
            }

            foreach ( DFAState s in it )
            {
                if ( s == null )
                {
                    // ignore null states; some acylic DFA see this condition
                    // when inlining DFA (due to lacking of exit branch pruning?)
                    continue;
                }

                if ( s.IsAcceptState )
                {
                    // can't compute min,max,special,transition on accepts
                    _accept[s.StateNumber] = s.GetUniquelyPredictedAlt();
                }
                else
                {
                    CreateMinMaxTables( s );
                    CreateTransitionTableEntryForState( s );
                    CreateSpecialTable( s );
                    CreateEOTAndEOFTables( s );
                }
            }

            // now that we have computed list of specialStates, gen code for 'em
            for ( int i = 0; i < _specialStates.Count; i++ )
            {
                DFAState ss = _specialStates[i];
                StringTemplate stateST = generator.GenerateSpecialState( ss );
                _specialStateSTs.Add( stateST );
            }

            // check that the tables are not messed up by encode/decode
            /*
            testEncodeDecode(min);
            testEncodeDecode(max);
            testEncodeDecode(accept);
            testEncodeDecode(special);
            [email protected]("min="+min);
            [email protected]("max="+max);
            [email protected]("eot="+eot);
            [email protected]("eof="+eof);
            [email protected]("accept="+accept);
            [email protected]("special="+special);
            [email protected]("transition="+transition);
            */
        }