Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="" method="post">
- <textarea name="parse"></textarea><br>
- <input type="submit" value="run your code!">
- </form>
- <br><br><br><br>
- <?php
- ini_set('display_errors',1);
- ini_set('display_startup_errors',1);
- error_reporting(-1);
- if(isset($_POST) && isset($_POST["parse"]))
- echo parse($_POST["parse"]);
- else
- echo parse("If 10 == 10, then here will appear a <<IF [10] == [10] FI>>, but there is also the possibility to get a <<IF [30] < [10] FI>>,<br>
- therefor the IF clause I wrote there have to be wrong, but that is not the case.<br> But it can also happen a error like this: <<IF[30]=[30]FI>><br>
- soon there will be the possibility to add variables, they will be used like this:<br>
- define: <<[HalloWelt]=[13]>><br>
- and output: <<ECHO[HalloWelt]ECHO>><br>
- Now a litte test: <<IF[<<IF[10]==[10]FI>>]==[0]FI>>");
- function parse($toParse) {
- $variables = [];
- if(preg_match_all("/<<+(.*?)>>/", $toParse, $matches)) {
- foreach($matches[1] as $match) {
- $save = $match;
- $match = str_replace(" ", "", $match);
- if(preg_match_all("/if+(.*?)fi/i", $match, $ifs)) {
- foreach($ifs[1] as $if) {
- $if = parse($if);
- $if = str_replace(">", "", $if, $gt);
- $if = str_replace("<", "", $if, $lt);
- $if = str_replace("==", "", $if, $eq);
- preg_match_all("/\[+(.*?)\]/", $if, $params);
- if(count($params[1]) > 2 || count($params[1]) < 2) die ("Syntax Error!");
- if($gt == 1 && $lt != 1 && $eq != 1) {
- if($params[1][0] > $params[1][1])
- $toParse = str_replace("<<".$save.">>","1", $toParse);
- else
- $toParse = str_replace("<<".$save.">>","0", $toParse);
- } else if($gt != 1 && $lt == 1 && $eq != 1) {
- if($params[1][0] < $params[1][1])
- $toParse = str_replace("<<".$save.">>","1", $toParse);
- else
- $toParse = str_replace("<<".$save.">>","0", $toParse);
- } else if($gt != 1 && $lt != 1 && $eq == 1) {
- if($params[1][0] == $params[1][1])
- $toParse = str_replace("<<".$save.">>","1", $toParse);
- else
- $toParse = str_replace("<<".$save.">>","0", $toParse);
- } else {
- $toParse = str_replace("<<".$save.">>","Syntax Error!", $toParse);
- }
- }
- }
- else if(preg_match_all("/echo+(.*?)echo/i", $match, $echos)) {
- foreach($echos[1] as $echo) {
- preg_match_all("/\[+(.*?)\]/", $echo, $params);
- if(count($params[1]) == 1)
- $toParse = str_replace("<<".$save.">>",$variables[strtolower($params[1][0])], $toParse);
- else
- $toParse = str_replace("<<".$save.">>","Syntax Error!", $toParse);
- }
- } else {
- $match = str_replace("=", "", $match, $ct);
- if($ct < 1 || $ct > 1)
- $toParse = str_replace("<<".$save.">>","Syntax Error!", $toParse);
- else {
- preg_match_all("/\[+(.*?)\]/", $match, $params);
- if(count($params[1]) == 2) {
- $variables[strtolower($params[1][0])] = $params[1][1];
- $toParse = str_replace("<<".$save.">>","", $toParse);
- } else
- $toParse = str_replace("<<".$save.">>","Syntax Error!", $toParse);
- }
- }
- }
- }
- return $toParse;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement