Guest User

Untitled

a guest
May 20th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <p>Parser</p>
  2. <?php
  3. $onp = '';
  4. $tablica = array();
  5. $tabela = array();
  6. include('objekty.php');
  7. include('funkcje.php');
  8. if ($_POST['wyslij'] == 'Wy¶lij')
  9. {
  10. echo "Wynik parsera:</br>";
  11. $text = $_POST['tekst'];
  12. $wynik = '';
  13. while (strlen($text) > 0)
  14. {
  15. $a = substr($text,0,1);
  16. if ($a == '+')
  17. {
  18. $text = substr($text,1);
  19. $tablica[] = new obiekt(1,'+');
  20. } elseif ($a == '-')
  21. {
  22. $text = substr($text,1);
  23. $tablica[] = new obiekt(1,'-');
  24. } elseif ($a == ' ')
  25. {
  26. $text = substr($text,1);
  27. } elseif ($a == "\r\n" || $a == "\n" || $a == "\r" || $a == "\t")
  28. {
  29. $text = substr($text,1);
  30. } elseif ($a == '*')
  31. {
  32. $text = substr($text,1);
  33. $tablica[] = new obiekt(1,'*');
  34. } elseif ($a == '/')
  35. {
  36. $text = substr($text,1);
  37. $tablica[] = new obiekt(1,'/');
  38. } elseif ($a == '(')
  39. {
  40. $text = substr($text,1);
  41. $tablica[] = new obiekt(1,'(');
  42. } elseif ($a == ')')
  43. {
  44. $text = substr($text,1);
  45. $tablica[] = new obiekt(1,')');
  46. } elseif (ereg("[0-9]",substr($text,0,1)))
  47. {
  48. $w = substr($text,0,1);
  49. $text = substr($text,1);
  50. while (ereg("[0-9]",substr($text,0,1)))
  51. {
  52. $w .= substr($text,0,1);
  53. $text = substr($text,1);
  54. }
  55. if (substr($text,0,1) == ".")
  56. {
  57. $text = substr($text,1);
  58. $w .= ".";
  59. if (!ereg("[0-9]",substr($text,0,1)))
  60. {
  61. $text = "";
  62. $blad = 1;
  63. }
  64. while (ereg("[0-9]",substr($text,0,1)))
  65. {
  66. $w .= substr($text,0,1);
  67. $text = substr($text,1);
  68. }
  69. $tablica[] = new obiekt(3,$w);
  70. if ($blad == 1)
  71. {
  72. $wynik .= "bł±d";
  73. }
  74. } else
  75. $tablica[] = new obiekt(2,$w);
  76. } elseif (ereg("[a-zA-Z]",substr($text,0,1)))
  77. {
  78. $w = substr($text,0,1);
  79. $text = substr($text,1);
  80. while (ereg("[a-zA-Z0-9]",substr($text,0,1)))
  81. {
  82. $w .= substr($text,0,1);
  83. $text = substr($text,1);
  84. }
  85. $tablica[] = new obiekt(4,$w);
  86. } else
  87. {
  88. $wynik = "bł±d";
  89. $text = "";
  90. }
  91. }
  92. echo $wynik == '' ? 'Wszystko OK' : 'BŁAD';
  93. //$tab = $tablica;
  94. //W (1, $tablica, $tabela);
  95. }
  96. ?>
Add Comment
Please, Sign In to add comment