Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace tablazatos_elemzo
- {
- public partial class Form1 : Form
- {
- Stack<string> stack = new Stack<string>();
- bool ures_e = false;
- static string szalag = "i + i * i";
- string[] splittedSzalag = szalag.Split(' ');
- string[][] matrix = new string[][]
- {
- new string[] {"error", "+", "*", "(", ")", "i", "#"},
- new string[] {"E", "error", "error", "(TE', 1)", "error", "(TE', 1)", "error"},
- new string[] {"E'", "(+TE', 2)", "error", "error", "(ε, 3)", "error", "(ε, 3)"},
- new string[] {"T", "error", "error", "(FT',4)", "error", "(FT',4)", "error"},
- new string[] {"T'", "(ε, 6)", "(*FT', 5)", "error", "(ε, 6)", "error", "(ε, 6)"},
- new string[] {"F", "error", "error", "((E), 7)", "error", "(i, 8)", "error"},
- new string[] {"+", "pop", "error", "error", "error", "error", "error"},
- new string[] {"*", "error", "pop", "error", "error", "error", "error"},
- new string[] {"(", "error", "error", "pop", "error", "error", "error"},
- new string[] {")", "error", "error", "error", "pop", "error", "error"},
- new string[] {"i", "error", "error", "error", "error", "pop", "error"},
- new string[] {"#", "error", "error", "error", "error", "error", "elfogad"},
- };
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- stack.Push("E");
- for (int i = 0; i < matrix[0].Length; i++)
- {
- dataGridView1.Columns.Add(i.ToString(), matrix[0][i]);
- }
- for (
- int i = 1; i < matrix.GetLength(0); i++)
- {
- dataGridView1.Rows.Add(matrix[i]);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- label1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString(); //aktuális cella sorazonosítóját adja meg
- }
- private void button2_Click(object sender, EventArgs e)
- {
- int index = 0;
- while (index < szalag.Length)
- {
- string aktElem = stack.Peek();
- int oszlopIndex = 1;
- int sorIndex = 0;
- string szabalyokSorszama = "";
- while (oszlopIndex < dataGridView1.Columns.Count - 1 && dataGridView1.Columns[oszlopIndex].HeaderText != splittedSzalag[index])
- {
- oszlopIndex++;
- }
- while (sorIndex < dataGridView1.Rows.Count - 1 && dataGridView1.Rows[sorIndex].Cells[0].Value.ToString() != aktElem)
- {
- sorIndex++;
- }
- TextboxFill(String.Format(">>> Szalag index: {0}\r\n>>> Oszlop index: {1}\r\n>>> Sor index: {2}", index, oszlopIndex, sorIndex));
- string adat = dataGridView1.Rows[sorIndex].Cells[oszlopIndex].Value.ToString();
- string tisztaAdat = "error";
- bool szabalyVolt = false;
- switch (adat)
- {
- case "error":
- TextboxFill(adat);
- return;
- case "elfogad":
- TextboxFill(adat);
- break;
- case "pop":
- stack.Pop();
- index++;
- TextboxFill(adat);
- break;
- default:
- tisztaAdat = adat.Substring(adat.IndexOf("(") + 1, adat.IndexOf(",")-1);
- szabalyokSorszama += adat.Substring(adat.IndexOf(",") + 1, 1);
- szabalyVolt = true;
- TextboxFill(adat);
- break;
- }
- if (szabalyVolt)
- {
- stack.Pop();
- if (tisztaAdat != "ε")
- {
- for (int i = tisztaAdat.Length - 1; i >= 0; i--)
- {
- if (tisztaAdat[i].ToString() == "'")
- {
- stack.Push(tisztaAdat[i-1].ToString() + tisztaAdat[i].ToString());
- }
- else stack.Push(tisztaAdat[i].ToString());
- }
- }
- }
- }
- }
- private void kiszed()
- {
- // ide kell majd beletenni a feljebbi részt
- }
- void TextboxFill(string msg)
- {
- if (InvokeRequired)
- {
- Invoke(new Action(() => textBox1.Text += msg + "\r\n"));
- }
- else textBox1.Text += msg + "\r\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement