private void CompileClick(object sender, EventArgs e) { ErrorCount = 0; Parser parser; error_list.Items.Clear(); lbl_stats.Text = ""; txt_out.Text = ""; if (ParentContainer.Panel2Collapsed) { ParentContainer.Panel2Collapsed = false; Tabs.SelectedIndex = 1; txt_out.Text = "Compiling .....\n"; } if (edit.Text.Length < 1) { MessageBox.Show("No Code To Compile It!!", "No Code", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { parser = new Parser(new Scanner(String2Stream(edit.Text))); try { IProgram prog = parser.Program(); StaticTypeCheck.Validate(prog); IProgram transformed = TypeTransformer.Transform(prog); txt_out.Text += transformed.Display(); txt_out.Text += "\n-------------------------------\n"; txt_out.Text += "\nResults:\n"; State state = Interpreter.Interpret(transformed); Code = state.Display(); txt_out.Text += Code; ParentContainer.Panel2Collapsed = true; lbl_stats.Text = "Successful Compiling"; } catch (IException ex) { txt_out.Text = ex.Type + " Error : " + ex.Message; ListViewItem lvi = new ListViewItem((++ErrorCount).ToString()); lvi.SubItems.Add(ex.Type); lvi.SubItems.Add(ex.File); lvi.SubItems.Add(ex.LineNumber.ToString()); lvi.SubItems.Add(ex.ColmunNumber.ToString()); lvi.SubItems.Add(ex.Message); error_list.Items.Add(lvi); lbl_stats.Text = "Failed Compiling"; Tabs.SelectedIndex = 0; } catch (Exception ex) { txt_out.Text = " Error : " + ex.Message; ListViewItem lvi = new ListViewItem((++ErrorCount).ToString()); lvi.SubItems.Add("Unkown"); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(ex.Message); error_list.Items.Add(lvi); lbl_stats.Text = "Failed Compiling"; } } }
public static State Interpret(IProgram p) { return(Interpret(p.functions()["main"].Body(), p.functions(), InitialState(p.Globals()))); }