Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <p>Parser</p>
- <?php
- $onp = '';
- $tablica = array();
- $tabela = array();
- include('objekty.php');
- include('funkcje.php');
- if ($_POST['wyslij'] == 'Wy¶lij')
- {
- echo "Wynik parsera:</br>";
- $text = $_POST['tekst'];
- $wynik = '';
- while (strlen($text) > 0)
- {
- $a = substr($text,0,1);
- if ($a == '+')
- {
- $text = substr($text,1);
- $tablica[] = new obiekt(1,'+');
- } elseif ($a == '-')
- {
- $text = substr($text,1);
- $tablica[] = new obiekt(1,'-');
- } elseif ($a == ' ')
- {
- $text = substr($text,1);
- } elseif ($a == "\r\n" || $a == "\n" || $a == "\r" || $a == "\t")
- {
- $text = substr($text,1);
- } elseif ($a == '*')
- {
- $text = substr($text,1);
- $tablica[] = new obiekt(1,'*');
- } elseif ($a == '/')
- {
- $text = substr($text,1);
- $tablica[] = new obiekt(1,'/');
- } elseif ($a == '(')
- {
- $text = substr($text,1);
- $tablica[] = new obiekt(1,'(');
- } elseif ($a == ')')
- {
- $text = substr($text,1);
- $tablica[] = new obiekt(1,')');
- } elseif (ereg("[0-9]",substr($text,0,1)))
- {
- $w = substr($text,0,1);
- $text = substr($text,1);
- while (ereg("[0-9]",substr($text,0,1)))
- {
- $w .= substr($text,0,1);
- $text = substr($text,1);
- }
- if (substr($text,0,1) == ".")
- {
- $text = substr($text,1);
- $w .= ".";
- if (!ereg("[0-9]",substr($text,0,1)))
- {
- $text = "";
- $blad = 1;
- }
- while (ereg("[0-9]",substr($text,0,1)))
- {
- $w .= substr($text,0,1);
- $text = substr($text,1);
- }
- $tablica[] = new obiekt(3,$w);
- if ($blad == 1)
- {
- $wynik .= "bł±d";
- }
- } else
- $tablica[] = new obiekt(2,$w);
- } elseif (ereg("[a-zA-Z]",substr($text,0,1)))
- {
- $w = substr($text,0,1);
- $text = substr($text,1);
- while (ereg("[a-zA-Z0-9]",substr($text,0,1)))
- {
- $w .= substr($text,0,1);
- $text = substr($text,1);
- }
- $tablica[] = new obiekt(4,$w);
- } else
- {
- $wynik = "bł±d";
- $text = "";
- }
- }
- echo $wynik == '' ? 'Wszystko OK' : 'BŁAD';
- //$tab = $tablica;
- //W (1, $tablica, $tabela);
- }
- ?>
Add Comment
Please, Sign In to add comment