Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.Eventing.Reader;
  4. using System.Linq;
  5. using System.Net.NetworkInformation;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9.  
  10. namespace translatoryZadanie1
  11. {
  12. public class Analizer
  13. {
  14. private List<Variable> lista = new List<Variable>();
  15. private int pozycja = 0;
  16. private string currentSymbol = "";
  17. public bool testVar = false;
  18. public bool skipToTest = false;
  19. public int nawiasy = 0;
  20. private Label label;
  21.  
  22. public Analizer(List<Variable> lista,string currentSymbol, Form1 form)
  23. {
  24. this.lista = lista;
  25. label = form.label1;
  26. this.currentSymbol = currentSymbol;
  27. }
  28.  
  29. public void Wyrazenie()
  30. {
  31.  
  32. Skladnik();
  33. ResztaWyrazenie();
  34. }
  35.  
  36. private void ResztaWyrazenie()
  37. {
  38. if (currentSymbol == "plus" || currentSymbol == "minus")
  39. {
  40. Accept(currentSymbol);
  41. Skladnik();
  42. ResztaWyrazenie();
  43. }
  44. }
  45.  
  46. private void Accept(string expectedSymbol)
  47. {
  48. if (currentSymbol == expectedSymbol)
  49. {
  50. currentSymbol = NextSymbol().Type;
  51. }
  52. else
  53. {
  54. throw new Exception($"Oczekiwany {expectedSymbol}");
  55. }
  56. }
  57.  
  58. private Variable NextSymbol()
  59. {
  60. if (pozycja < lista.Count)
  61. {
  62. return lista[++pozycja];
  63. }
  64. return new Variable("$", "koniec") ;
  65. }
  66.  
  67. private void Skladnik()
  68. {
  69. Czynnik();
  70. ResztaSkladnika();
  71. }
  72.  
  73. private void ResztaSkladnika()
  74. {
  75. if (currentSymbol == "mnożenie" || currentSymbol == "ukośnik")
  76. {
  77. Accept(currentSymbol);
  78. Czynnik();
  79. ResztaSkladnika();
  80. }
  81.  
  82. }
  83.  
  84. private void Czynnik()
  85. {
  86. if (currentSymbol == "Identyfikator" || currentSymbol== "Liczba całkowita" || currentSymbol == "Liczba zmienno przecinkowa")
  87. {
  88.  
  89. Accept(currentSymbol);
  90. }
  91. else
  92. {
  93. Accept("nawias_otwierający");
  94. Wyrazenie();
  95. Accept("nawias_zamykający");
  96. }
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement