Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp5
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. String str = textBox1.Text;
  23. String CS = "H";
  24. label1.Text = "";
  25. string[] strM = str.Split(' ');
  26. // int i = 0;
  27. int L = strM.Length - 1;
  28. do
  29. {
  30. String c = "";
  31. for (int i = 0; i <= L; i++)
  32. {
  33. c += strM[i]+ " ";
  34. }
  35. label1.Text += c + CS + "=>";
  36.  
  37. switch (CS)
  38. {
  39. case ("H"):
  40. {
  41. if (strM[L] == "e")
  42. {
  43. CS = "BC";
  44. }
  45. else
  46. {
  47. CS = "Error";
  48. }
  49. break;
  50. }
  51. case ("BC"):
  52. {
  53. if (strM[L] == "else" && strM[L - 1] == "e")
  54. {
  55. L--;
  56. CS = "B";
  57. }
  58. else if (strM[L] == "c")
  59. {
  60. CS = "A";
  61. }
  62. else
  63. {
  64. CS = "Error";
  65. }
  66. break;
  67. }
  68. case ("S"):
  69. {
  70. if (strM[L] == "else" && strM[L - 1] == "e")
  71. {
  72. L--;
  73. CS = "B";
  74. }
  75. else if (strM[L] == "c")
  76. {
  77. CS = "A";
  78. }
  79. else
  80. {
  81. CS = "Error";
  82. }
  83. break;
  84. }
  85. case ("B"):
  86. {
  87.  
  88. if (strM[L] == "c")
  89. {
  90. CS = "A";
  91. }
  92. else
  93. {
  94. CS = "Error";
  95. }
  96. break;
  97. }
  98. case ("A"):
  99. {
  100. if(strM[L]=="if")
  101. {
  102. CS = "S";
  103. }
  104. else
  105. {
  106. CS = "Error";
  107. }
  108. break;
  109. }
  110. }
  111. L--;
  112. } while (L !=-1);
  113.  
  114. if (CS == "Error")
  115. {
  116. MessageBox.Show("Строка не принадлежит грамматике");
  117. }
  118. else
  119. {
  120. label1.Text += CS;
  121. MessageBox.Show("Строка принадлежит грамматике");
  122. }
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement