Ejemplo n.º 1
0
        /*
         * Function: make_dtrans
         * Description: Creates uncompressed CDTrans transition table.
         */
        //private void make_dtrans()
        private static void make_dtrans(Spec s)
        {
            Dfa dfa;
            int nextstate;

            Console.WriteLine("Working on DFA states.");

            /* Reference passing type and initializations. */
            s.InitUnmarkedDFA();

            /* Allocate mapping array. */
            int nstates = s.state_rules.Length;

            s.state_dtrans = new int[nstates];

            for (int istate = 0; istate < nstates; istate++)
            {
                /* Create start state and initialize fields. */

                Bunch bunch = new Bunch(s.state_rules[istate]);

                bunch.e_closure();
                add_to_dstates(s, bunch);

                s.state_dtrans[istate] = s.dtrans_list.Count;

                /* Main loop of DTrans creation. */
                while (null != (dfa = s.GetNextUnmarkedDFA()))
                {
                    Console.Write(".");
#if DEBUG
                    Utility.assert(!dfa.IsMarked());
#endif
                    /* Get first unmarked node, then mark it. */
                    dfa.SetMarked();

                    /* Allocate new DTrans, then initialize fields. */
                    DTrans dt = new DTrans(s, dfa);

                    /* Set dt array for each character transition. */
                    for (int i = 0; i < s.dtrans_ncols; i++)
                    {
                        /* Create new dfa set by attempting character transition. */
                        bunch.move(dfa, i);
                        if (!bunch.IsEmpty())
                        {
                            bunch.e_closure();
                        }
#if DEBUG
                        Utility.assert((null == bunch.GetNFASet() &&
                                        null == bunch.GetNFABit()) ||
                                       (null != bunch.GetNFASet() &&
                                        null != bunch.GetNFABit()));
#endif
                        /* Create new state or set state to empty. */
                        if (bunch.IsEmpty())
                        {
                            nextstate = DTrans.F;
                        }
                        else
                        {
                            nextstate = in_dstates(s, bunch);

                            if (nextstate == NOT_IN_DSTATES)
                            {
                                nextstate = add_to_dstates(s, bunch);
                            }
                        }
#if DEBUG
                        Utility.assert(nextstate < s.dfa_states.Count);
#endif
                        dt.SetDTrans(i, nextstate);
                    }
#if DEBUG
                    Utility.assert(s.dtrans_list.Count == dfa.GetLabel());
#endif
#if DEBUG
                    StringBuilder sb1 = new StringBuilder(Properties.Settings.Default.MaxStr);
                    sb1.Append("Current count = " + s.dtrans_list.Count + "\n");
                    for (int i1 = 0; i1 < dt.GetDTransLength(); i1++)
                    {
                        sb1.Append(dt.GetDTrans(i1) + ",");
                    }
                    sb1.Append("end\n");
                    Console.Write(sb1.ToString());
#endif
                    s.dtrans_list.Add(dt);
                }
            }
            Console.WriteLine("");
        }