private void button1_Click(object sender, EventArgs e) { LexAnalyzator la = new LexAnalyzator(); String laResult = la.process(textBox1.Text); if (la.HasErrors) { textBox2.Text = laResult; } else { textBox3.Text = laResult; SA3 sa = new SA3(); MessageBox.Show(sa.process(la.getTokens())); if (!sa.Errors) { la.process(textBox1.Text); IntermediateCodeGenerator icg = new IntermediateCodeGenerator(la.getTokens()); icg.process(); dataGridView1.ColumnCount = 3; dataGridView1.Columns[0].Width = dataGridView1.Columns[0].Width + 650; dataGridView1.Columns[1].Width = dataGridView1.Columns[1].Width + 100; dataGridView1.Columns[0].Name = "ПОЛИЗ"; dataGridView1.Columns[1].Name = "СТЕК"; dataGridView1.Columns[2].Name = "ВХОД"; foreach (ICGInfo info in icg.Information) { String[] row = new String[3]; row[0] = info.Result; row[1] = info.Stack; row[2] = info.Input; dataGridView1.Rows.Add(row); } textBox2.Text = icg.Information[icg.Information.Count - 1].Result; Executor exec = new Executor(icg.Result, la.getIDs().Cast <ID>() .ToList()); while (!exec.process()) { exec.ReadVarValue = Double.Parse( Microsoft.VisualBasic.Interaction.InputBox("Будь ласка, введіть значення " + exec.ReadVar + ":", "Введіть значення", "0")); } MessageBox.Show("ПРОГРАМА УСПІШНО ВИКОНАНА\r\n" + exec.Result); } } }
private void button2_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; LexAnalyzator la = new LexAnalyzator(); la.process(textBox1.Text); if (!la.HasErrors) { sa = new SA3(); textBox2.Text = sa.process(la.getTokens()); if (!sa.Errors) { HashSet <String> ids = new HashSet <String>(); foreach (PolishNotationElement el in sa.PolishNotation) { if (el.IsVariable) { ids.Add(el.Value); } textBox4.Text += el.Value + " "; } dataGridView1.ColumnCount = 2; dataGridView1.Columns[0].Name = "ЗМІННА"; dataGridView1.Columns[1].Name = "ЗНАЧЕННЯ"; foreach (String id in ids) { String[] row = new String[5]; row[0] = id; row[1] = "0"; dataGridView1.Rows.Add(row); } List <PolishNotationElement> toBeCalculated = new List <PolishNotationElement>(); foreach (PolishNotationElement el in sa.PolishNotation) { if (!el.IsVariable) { toBeCalculated.Add(el); } else { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value.ToString().Equals(el.Value)) { toBeCalculated.Add(new PolishNotationElement(row.Cells[1].Value.ToString(), false)); break; } } } } textBox3.Text = ExpressionCalculator.calculate(toBeCalculated); } dataGridView2.Rows.Clear(); dataGridView2.ColumnCount = 5; dataGridView2.Columns[1].Width = dataGridView2.Columns[1].Width + 80; dataGridView2.Columns[3].Width = dataGridView2.Columns[3].Width + 200; dataGridView2.Columns[4].Width = dataGridView2.Columns[4].Width * 2; dataGridView2.Columns[0].Name = "СТЕК"; dataGridView2.Columns[1].Name = "ЗНАК"; dataGridView2.Columns[2].Name = "ВХІД"; dataGridView2.Columns[3].Name = "ОСНОВА"; dataGridView2.Columns[4].Name = "ПОЛІЗ"; if (sa.Information != null) { foreach (AscentSAInfo info in sa.Information) { String[] row = new String[5]; row[0] = info.Stack; row[1] = info.Sign; row[2] = info.Input; row[3] = info.Base; row[4] = info.PolishNote; dataGridView2.Rows.Add(row); } } } else { textBox2.Text = "ПОМИЛКА У ВИРАЗІ"; } }