예제 #1
0
        private void fix_dtrans()
        {
            List <DTrans> list = new List <DTrans>();
            int           num  = this.spec.state_dtrans.Length;

            for (int i = 0; i < num; i++)
            {
                if (-1 != this.spec.state_dtrans[i])
                {
                    this.spec.state_dtrans[i] = this.ingroup[this.spec.state_dtrans[i]];
                }
            }
            num = this.group.Count;
            for (int i = 0; i < num; i++)
            {
                List <DTrans> list2  = this.group[i];
                DTrans        dTrans = list2[0];
                list.Add(dTrans);
                for (int j = 0; j < this.spec.dtrans_ncols; j++)
                {
                    if (-1 != dTrans.GetDTrans(j))
                    {
                        dTrans.SetDTrans(j, this.ingroup[dTrans.GetDTrans(j)]);
                    }
                }
            }
            this.group            = null;
            this.spec.dtrans_list = list;
        }
예제 #2
0
파일: Emit.cs 프로젝트: xmaxmex/Phalanger
 private void print_details()
 {
     Console.WriteLine("---------------------- Transition Table ----------------------");
     for (int i = 0; i < this.spec.row_map.Length; i++)
     {
         Console.Write("State " + i);
         Accept accept = this.spec.accept_list[i];
         if (accept == null)
         {
             Console.WriteLine(" [nonaccepting]");
         }
         else
         {
             Console.Write(" [accepting, ");
             accept.Dump();
             Console.Write("]");
         }
         DTrans dTrans = this.spec.dtrans_list[this.spec.row_map[i]];
         bool   flag   = false;
         int    num    = dTrans.GetDTrans(this.spec.col_map[0]);
         if (-1 != num)
         {
             flag = true;
             Console.Write("\tgoto " + num.ToString() + " on [");
         }
         for (int j = 1; j < this.spec.dtrans_ncols; j++)
         {
             int dTrans2 = dTrans.GetDTrans(this.spec.col_map[j]);
             if (num == dTrans2)
             {
                 if (-1 != num)
                 {
                     Console.Write((char)j);
                 }
             }
             else
             {
                 num = dTrans2;
                 if (flag)
                 {
                     Console.WriteLine("]");
                     flag = false;
                 }
                 if (-1 != num)
                 {
                     flag = true;
                     Console.Write("\tgoto " + num.ToString() + " on [" + char.ToString((char)j));
                 }
             }
         }
         if (flag)
         {
             Console.WriteLine("]");
         }
     }
     Console.WriteLine("---------------------- Transition Table ----------------------");
 }
예제 #3
0
        private bool col_equiv(int col1, int col2)
        {
            int count = this.spec.dtrans_list.Count;

            for (int i = 0; i < count; i++)
            {
                DTrans dTrans = this.spec.dtrans_list[i];
                if (dTrans.GetDTrans(col1) != dTrans.GetDTrans(col2))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #4
0
파일: Emit.cs 프로젝트: xmaxmex/Phalanger
 private void EmitTableNxt()
 {
     this.outstream.WriteLine("private static int[,] nextState = new int[,]");
     this.outstream.WriteLine("{");
     this.outstream.Indent++;
     for (int i = 0; i < this.spec.dtrans_list.Count; i++)
     {
         DTrans dTrans = this.spec.dtrans_list[i];
         if (i > 0)
         {
             this.outstream.WriteLine(",");
         }
         this.outstream.Write("{ ");
         for (int j = 0; j < this.spec.dtrans_ncols; j++)
         {
             if (j > 0)
             {
                 this.outstream.Write(", ");
             }
             this.outstream.Write(dTrans.GetDTrans(j));
         }
         this.outstream.Write(" }");
     }
     this.outstream.WriteLine();
     this.outstream.Indent--;
     this.outstream.WriteLine("};");
     this.outstream.WriteLine();
 }
예제 #5
0
        private void col_copy(int dest, int src)
        {
            int count = this.spec.dtrans_list.Count;

            for (int i = 0; i < count; i++)
            {
                DTrans dTrans = this.spec.dtrans_list[i];
                dTrans.SetDTrans(dest, dTrans.GetDTrans(src));
            }
        }
예제 #6
0
        private bool row_equiv(int row1, int row2)
        {
            DTrans dTrans  = this.spec.dtrans_list[row1];
            DTrans dTrans2 = this.spec.dtrans_list[row2];

            for (int i = 0; i < this.spec.dtrans_ncols; i++)
            {
                if (dTrans.GetDTrans(i) != dTrans2.GetDTrans(i))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #7
0
        private void minimize()
        {
            this.init_groups();
            int num  = this.group.Count;
            int num2 = num - 1;

            while (num2 != num)
            {
                num2 = num;
                for (int i = 0; i < num; i++)
                {
                    List <DTrans> list = this.group[i];
                    int           num3 = list.Count;
                    if (num3 > 1)
                    {
                        List <DTrans> list2  = new List <DTrans>();
                        bool          flag   = false;
                        DTrans        dTrans = list[0];
                        for (int j = 1; j < num3; j++)
                        {
                            DTrans dTrans2 = list[j];
                            for (int k = 0; k < this.spec.dtrans_ncols; k++)
                            {
                                int dTrans3 = dTrans.GetDTrans(k);
                                int dTrans4 = dTrans2.GetDTrans(k);
                                if (dTrans3 != dTrans4 && (dTrans3 == -1 || dTrans4 == -1 || this.ingroup[dTrans4] != this.ingroup[dTrans3]))
                                {
                                    list.RemoveAt(j);
                                    j--;
                                    num3--;
                                    list2.Add(dTrans2);
                                    if (!flag)
                                    {
                                        flag = true;
                                        num++;
                                        this.group.Add(list2);
                                    }
                                    this.ingroup[dTrans2.Label] = this.group.Count - 1;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine(this.group.Count + " states after removal of redundant states.");
            this.fix_dtrans();
        }
예제 #8
0
파일: Emit.cs 프로젝트: notfarfromorion/Lex
        private void YYNXT_table()
        {
            int           size     = spec.dtrans_list.Count;
            int           lastelem = size - 1;
            int           lastcol  = spec.dtrans_ncols - 1;
            StringBuilder sb       = new StringBuilder(Lex.MAXSTR);

            sb.Append("private static int[,] yy_nxt = new int[,]\n  {\n");
            for (int elem = 0; elem < size; elem++)
            {
                DTrans cdt_list = (DTrans)spec.dtrans_list[elem];
#if DEBUG
                Utility.assert(spec.dtrans_ncols <= cdt_list.GetDTransLength());
#endif
                sb.Append("  { ");
                for (int i = 0; i < spec.dtrans_ncols; i++)
                {
                    sb.Append(cdt_list.GetDTrans(i));
                    if (i < lastcol)
                    {
                        sb.Append(",");
                        if (((i + 1) % 8) == 0)
                        {
                            sb.Append("\n   ");
                        }
                        else
                        {
                            sb.Append(" ");
                        }
                    }
                }
                sb.Append(" }");
                if (elem < lastelem)
                {
                    sb.Append(",");
                }
                sb.Append("\n");
            }
            sb.Append("  };\n");
            outstream.Write(sb.ToString());
        }
예제 #9
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();

            Console.WriteLine("done init");
            /* 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(Lex.MAXSTR);
                    sb1.Append("Current count = " + s.dtrans_list.Count.ToString() + "\n");
                    for (int i1 = 0; i1 < dt.GetDTransLength(); i1++)
                    {
                        sb1.Append(dt.GetDTrans(i1).ToString() + ",");
                    }
                    sb1.Append("end\n");
                    Console.Write(sb1.ToString());
#endif
                    s.dtrans_list.Add(dt);
                }
            }
            Console.WriteLine("");
        }