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 WindowsFormsApp5
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String str = textBox1.Text;
- String CS = "H";
- label1.Text = "";
- string[] strM = str.Split(' ');
- // int i = 0;
- int L = strM.Length - 1;
- do
- {
- String c = "";
- for (int i = 0; i <= L; i++)
- {
- c += strM[i]+ " ";
- }
- label1.Text += c + CS + "=>";
- switch (CS)
- {
- case ("H"):
- {
- if (strM[L] == "e")
- {
- CS = "BC";
- }
- else
- {
- CS = "Error";
- }
- break;
- }
- case ("BC"):
- {
- if (strM[L] == "else" && strM[L - 1] == "e")
- {
- L--;
- CS = "B";
- }
- else if (strM[L] == "c")
- {
- CS = "A";
- }
- else
- {
- CS = "Error";
- }
- break;
- }
- case ("S"):
- {
- if (strM[L] == "else" && strM[L - 1] == "e")
- {
- L--;
- CS = "B";
- }
- else if (strM[L] == "c")
- {
- CS = "A";
- }
- else
- {
- CS = "Error";
- }
- break;
- }
- case ("B"):
- {
- if (strM[L] == "c")
- {
- CS = "A";
- }
- else
- {
- CS = "Error";
- }
- break;
- }
- case ("A"):
- {
- if(strM[L]=="if")
- {
- CS = "S";
- }
- else
- {
- CS = "Error";
- }
- break;
- }
- }
- L--;
- } while (L !=-1);
- if (CS == "Error")
- {
- MessageBox.Show("Строка не принадлежит грамматике");
- }
- else
- {
- label1.Text += CS;
- MessageBox.Show("Строка принадлежит грамматике");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement