Ejemplo n.º 1
0
 private string getStrFromGrammerAndDFA(InputGrammer inputGrammer, DFAGraphBase dFAGraph)
 {
     return(string.Format("\r\n产生式如下(编号从0开始)\r\n\r\n{0}\r\nDFA集族如下\r\n\r\n{1}", inputGrammer.ToString(), dFAGraph.ToString()));
 }
Ejemplo n.º 2
0
    private void generateLRDFAInGrid <T>() where T : DFAGraphBase
    {
        string kind = typeof(T).Name;

        kind = kind.Substring(kind.IndexOf("From") + 4);
        try
        {
            try
            {
                inputGrammer = new InputGrammer(InputArea.Text);
                dFAGraph     = Activator.CreateInstance(typeof(T), new object[] { inputGrammer }) as T;
            }
            catch (TargetInvocationException ee)
            {
                throw ee.GetBaseException();
            }
            dataGridView.Columns.Clear();
            dataGridView.Rows.Clear();
            List <DFANode> dFANodes = dFAGraph.GetDFANodes;
            List <DFANode> srcs     = dFANodes.Where(i => i.degrees.Count != 0).ToList();
            List <string>  dsts     = dFANodes.Select(i => i.ID).ToList();


            List <string> cols = new List <string> {
                @"起点\终点"
            };
            cols.AddRange(dsts);

            // 列太多导致FillWeight过多时 ,winform DataGridView会爆掉
            int weight = 65535 / (cols.Count + 1);
            for (int i = 0; i < cols.Count; i++)
            {
                dataGridView.Columns.Add(cols[i], null);
                // 禁用排序
                dataGridView.Columns[i].SortMode   = DataGridViewColumnSortMode.NotSortable;
                dataGridView.Columns[i].FillWeight = weight;
            }

            // 行序号从小到大
            List <string> rows = srcs.Select(i => i.ID).Distinct().OrderBy(i => Convert.ToInt32(i)).ToList();
            foreach (string row in rows)
            {
                dataGridView.Rows.Add(row);
            }

            foreach (DFANode src in srcs)
            {
                int rowID = rows.IndexOf(src.ID);
                foreach (var degree in src.degrees)
                {
                    dataGridView.Rows[rowID].Cells[cols.IndexOf(degree.degreeOut)].Value = degree.translation;
                }
            }

            if (formDFADictionary == null)
            {
                formDFADictionary = new FormDFADictionary();
            }
            formDFADictionary.getTextData(dFAGraph.ToString());
            formDFADictionary.Show();


            labelOfTable.Text = kind + " DFA";
        }
        catch (NoValidGrammerException ee) { MessageBox.Show(ee.Message, ee.Message); }
        catch (ExpandException ee) { MessageBox.Show(ee.Message, "生成" + kind + " DFA失败"); }
    }