private void showTableMessage(string text) { if (formDFADictionary == null) { formDFADictionary = new FormDFADictionary(); } formDFADictionary.getTextData(text); formDFADictionary.Show(); }
private bool generateLLTableInGrid() { try { inputGrammer = new InputGrammer(InputArea.Text); ll1table = new LL1Table(inputGrammer); List <Item> tableData = ll1table.TableData; List <string> cols = new List <string> { "M(N,T)" }; cols.AddRange(tableData.Select(i => i.col).Distinct().ToList()); List <string> rows = tableData.Select(i => i.row).Distinct().ToList(); dataGridView.Columns.Clear(); dataGridView.Rows.Clear(); 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; } foreach (string row in rows) { dataGridView.Rows.Add(row); } foreach (Item item in tableData) { dataGridView.Rows[rows.IndexOf(item.row)].Cells[cols.IndexOf(item.col)].Value = item.data; } } catch (NoValidGrammerException ee) { MessageBox.Show(ee.Message, ee.Message); return(false); } catch (FailToGenerateLL1Exception ee) { MessageBox.Show(ee.Message, "生成LL(1)分析表失败"); return(false); } catch (ConflictException ee) { MessageBox.Show(ee.Message, "生成LL(1)分析表失败"); if (formDFADictionary == null) { formDFADictionary = new FormDFADictionary(); } formDFADictionary.getTextData(ee.reason); formDFADictionary.Show(); return(false); } return(true); }
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失败"); } }