static void Rule() { Expect(1); Node n; Symbol s = Symbol.Find(t.val); //look if already known if (s == null) { n = new Node(new Symbol(Node.nt, t.val)); } else { if (s.typ == Node.nt) { String message = "ERROR: Nonterminal symbol " + t.val + " has been defined multiple times."; EbnfForm.WriteLine(message); n = new Node(new Symbol(0, "BUG")); } else { //if only considered as terminal symbol until now s.typ = Node.nt; Symbol.terminalToNt(s.name); Symbol.terminalToNt(s.name); Node.terminalToNt(s.name); n = Node.Find(s.name); } } Expect(4); Expr(out n.sym.graph); Expect(5); Graph.Finish(n.sym.graph); }
private void menuItemHelpLink_Click(object sender, System.EventArgs e) { try { System.Diagnostics.Process.Start("manual.html"); } catch { EbnfForm.WriteLine("Help named manual.html was not found!"); } }
private void SwitchToRule(Symbol s) { currentSymbol = s; drawGrammar(); EbnfForm.WriteLine("Switched to rule: " + s.name + "."); foreach (MenuItem mi in menuItemRules.MenuItems) { mi.Checked = false; if (mi.Text == s.name) { mi.Checked = true; } } }
private void SetCurrentSymbol(object sender, System.EventArgs e) { rulehistory.Clear(); foreach (MenuItem mi in menuItemRules.MenuItems) { mi.Checked = false; } MenuItem temp = (MenuItem)sender; temp.Checked = true; menuItemSave.Enabled = true; menuItemCopy.Enabled = true; currentSymbol = Symbol.Find(temp.Text); rulehistory.Push(currentSymbol); this.drawGrammar(); EbnfForm.WriteLine("Switched to rule: " + currentSymbol.name + "."); }
public static void Init(string fileName) { FileStream s = null; try { s = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); Init(s); } catch (IOException) { EbnfForm.WriteLine("--- Cannot open file " + fileName); //System.Environment.Exit(1); } finally { if (s != null) { s.Close(); } } }
// save drawing in bitmap DrawArea as a jpeg file private void menuItemSave_Click(object sender, System.EventArgs e) { ImageFormat format = ImageFormat.Gif; SaveFileDialog sfd = new SaveFileDialog(); if (currentSymbol != null) { sfd.FileName = currentSymbol.name; } sfd.Filter = "GIF Files(*.GIF)|*.GIF|Windows Metafile (*.EMF)|*.EMF"; if (sfd.ShowDialog() == DialogResult.OK) { if (sfd.FileName.EndsWith(".EMF")) { saveEmf(sfd.FileName); } else { DrawArea.Save(sfd.FileName, format); } EbnfForm.WriteLine("Rule " + currentSymbol.name + " saved to " + sfd.FileName + "."); } sfd.Dispose(); }
public static string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text #endregion #region Methods public static void SynErr(int line, int col, int n) { string s; switch (n) { case 0: { s = "EOF expected"; break; } case 1: { s = "identifier expected"; break; } case 2: { s = "terminal expected"; break; } case 3: { s = "wrap expected"; break; } case 4: { s = "\"=\" expected"; break; } case 5: { s = "terminator expected"; break; } case 6: { s = "\"|\" expected"; break; } case 7: { s = "\"(\" expected"; break; } case 8: { s = "\")\" expected"; break; } case 9: { s = "\"[\" expected"; break; } case 10: { s = "\"]\" expected"; break; } case 11: { s = "\"{\" expected"; break; } case 12: { s = "\"}\" expected"; break; } case 13: { s = "??? expected"; break; } case 14: { s = "invalid Sym"; break; } default: s = "error " + n; break; } Console.WriteLine(Errors.errMsgFormat, line, col, s); EbnfForm.WriteLine("ERROR: Line: " + line + " Col: " + col + ": " + s); count++; }
// copy current symbol picture to clipboard private void menuItemCopy_Click(object sender, System.EventArgs e) { EbnfForm.WriteLine("Rule " + currentSymbol.name + " copied to clipboard."); Clipboard.SetDataObject(DrawArea, true); }
private void LoadGrammar(String path) { //put shortcut in menu to top position foreach (MenuItem mi in menuItemFile.MenuItems) { mi.Checked = false; if (mi.Text == path) { mi.Index = 6; mi.Checked = true; break; } } // Clear the existing nodes and symbols Symbol.nonterminals = new ArrayList(); Symbol.terminals = new ArrayList(); Node.nodes = new ArrayList(); currentSymbol = null; menuItemRules.MenuItems.Clear(); rulehistory.Clear(); Scanner.Init(path); Parser.Parse(); Node.Optimize(); int i; bool insert; foreach (Symbol s in Symbol.nonterminals) { MenuItem m = new MenuItem(s.name); i = 0; insert = false; foreach (MenuItem mi in menuItemRules.MenuItems) { if (m.Text.CompareTo(mi.Text) > 0) { i++; } else { menuItemRules.MenuItems.Add(i, m); insert = true; break; } } if (i > 0 && !insert) { menuItemRules.MenuItems.Add(i, m); } if (menuItemRules.MenuItems.Count == 0) { menuItemRules.MenuItems.Add(m); } m.Click += new System.EventHandler(this.SetCurrentSymbol); } menuItemRules.Enabled = true; this.drawGrammar(); EbnfForm.WriteLine("New grammar loaded from file " + path + "."); }