<?php
$flg = false;
$_POST ["compilerinput"] = file_get_contents ("./compiler2.txt");
if (strncmp($_POST ["compilerinput"], "COMPILER:", strlen ("COMPILER")) == 0) {
$_POST ["compilerinput"] = str_replace ("COMPILER:", "", $_POST ["compilerinput"]);
$flg = true;
exec ("rm *.png");
}
else
exit (1);
$_POST ["compilerinput"] = str_replace ("<", "<", $_POST ["compilerinput"]);
$_POST ["compilerinput"] = str_replace (">", ">", $_POST ["compilerinput"]);
$lexstream = $_POST ["compilerinput"];
$lexstream = str_replace ("\n", " ", $lexstream);
$lexstream = str_replace ("\t", " ", $lexstream);
$lexstream = str_replace ("\r", " ", $lexstream);
initall ();
statement ();
ends_canvas ();
plot_animate_create_output_str ();
echo $compiler_output_str;
$plot_timevarname_timed;
$compiler_output_str;
$time_n_count;
$plot_timed_interval_length;
$plot_fname;
$plot_animated_fname_prefix;
function initall () {
global $lexstreami;
global $loopcount;
global $flag_image_created;
global $plot_varname;
global $upper;
global $lower;
global $flag_interval_limits_initialized;
global $plot_varname_timed;
global $upper_timed;
global $lower_timed;
global $flag_interval_limits_initialized_timed;
global $plot_timevarname_timed;
global $compiler_output_str;
global $time_n_count;
global $plot_timed_interval_length;
global $plot_fname;
global $plot_animated_fname_prefix;
$lexstreami = 0;
$loopcount = 0;
$flag_image_created = false;
$plot_varname = "x";
$upper = 4.0;
$lower = -4.0;
$flag_interval_limits_initialized = false;
$plot_varname_timed = "x";
$upper_timed = 4.0;
$lower_timed = -4.0;
$flag_interval_limits_initialized_timed = false;
$plot_timevarname_timed = "t";
$compiler_output_str = "";
$time_n_count = 62;
$plot_timed_interval_length = 1000;
$plot_fname = "./yun7xplot.png";
$plot_animated_fname_prefix = "./yun7xplotanimated";
}
function is_illegal_sign () {
global $lexstream;
global $lexstreami;
if (strcmp (substr ($lexstream, $lexstreami, 1), "@") == 0)
return false;
else if (strcmp (substr ($lexstream, $lexstreami, 1), "&") == 0)
return true;
return false;
/* ... */
}
function is_not_float_sign () {
global $lexstreami;
global $lexstream;
$ch = substr ($lexstream, $lexstreami, 1);
if ((strcmp ($ch, "0") >= 0) && (strcmp ($ch, "9") <= 0)) {
return false;
}
if (strcmp ($ch, ".") != 0) {
if (strcmp ($ch, "e") != 0) {
if (strcmp ($ch, "E") != 0) {
if (strcmp ($ch, "_") != 0) {
return true;
}
return false;
}
return false;
}
return false;
}
return false;
}
function charstrval () {
global $lexstreami;
global $lexstream;
$retstr = "";
for ($i = 0; (strcasecmp (substr ($lexstream, $lexstreami+$i, 1), "a") >= 0) &&
(strcasecmp (substr ($lexstream, $lexstreami+$i, 1), "z") <= 0) &&
(($lexstreami+$i) < strlen ($lexstream)); $i++)
$retstr = $retstr . substr ($lexstream, $lexstreami+$i, 1);
return $retstr;
}
function lexer () {
global $lexstreami;
global $lexstream;
if ((strcmp( $retstr = lexer2 (), "NOSIGN")) != 0)
return $retstr;
else if ((($retflt = floatval (substr ($lexstream, $lexstreami, strlen ($lexstream) - $lexstreami))) != 0) ||
(strcmp (substr ($lexstream, $lexstreami, 1), "0") == 0)) {
while (true) {
if (strcmp( lexer3 (), "ILLEGALSIGN") == 0) {
break;
}
if (strcmp( $tmpretstr1 = lexer3 (), "NOSIGN") != 0) {
if (is_not_float_sign ()) {
break;
}
if (strcmp ($tmprestr1, "CODEENDS") == 0)
break;
}
if (is_not_float_sign ()) {
break;
}
$lexstreami++;
}
return $retflt;
}
else if (strcmp($retstr = charstrval (substr ($lexstream, $lexstreami, strlen ($lexstream) - $lexstreami)), "") != 0) {
$lexstreami += strlen ($retstr);
return $retstr;
}
else {
$lexstreami++;
return $retstr;
}
}
function lexer3 () {
global $lexstreami;
global $lexstream;
if ($lexstreami == strlen ($lexstream)) {
return "CODEENDS";
}
if (strcmp(substr ($lexstream, $lexstreami, 1), '+') == 0) {
return "+";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '-') == 0) {
return "-";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '*') == 0) {
return "*";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '/') == 0) {
return "/";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '%') == 0) {
return "%";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ';') == 0) {
return ";";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '(') == 0) {
return "(";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ')') == 0) {
return ")";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '[') == 0) {
return "[";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ']') == 0) {
return "]";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '$') == 0) {
return "$";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ',') == 0) {
return ",";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '@') == 0) {
return "@";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '<') == 0) {
if (strcmp(substr ($lexstream, $lexstreami+1, 1), '=') == 0) {
return "<=";
}
return "<";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '>') == 0) {
if (strcmp(substr ($lexstream, $lexstreami+1, 1), '=') == 0) {
return ">=";
}
return ">";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '=') == 0) {
if (strcmp(substr ($lexstream, $lexstreami+1, 1), '=') == 0) {
return "==";
}
return "=";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ':') == 0) {
if (strcmp(substr ($lexstream, $lexstreami+1, 1), '=') == 0) {
return ":=";
}
else
return "NOSIGN";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '!') == 0) {
if (strcmp(substr ($lexstream, $lexstreami+1, 1), '=') == 0) {
return "!=";
}
return "!";
}
else if (is_illegal_sign()) {
return "ILLEGALSIGN";
}
else {
return "NOSIGN";
}
}
function lexer2 () {
global $lexstreami;
global $lexstream;
if ($lexstreami == strlen ($lexstream)) {
return "CODEENDS";
}
if (strcmp(substr ($lexstream, $lexstreami, 1), '+') == 0) {
$lexstreami++;
return "+";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '-') == 0) {
$lexstreami++;
return "-";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '*') == 0) {
$lexstreami++;
return "*";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '/') == 0) {
$lexstreami++;
return "/";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '%') == 0) {
$lexstreami++;
return "%";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ';') == 0) {
$lexstreami++;
return ";";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '(') == 0) {
$lexstreami++;
return "(";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ')') == 0) {
$lexstreami++;
return ")";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '[') == 0) {
$lexstreami++;
return "[";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ']') == 0) {
$lexstreami++;
return "]";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '$') == 0) {
$lexstreami++;
return "$";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ',') == 0) {
$lexstreami++;
return ",";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '@') == 0) {
$lexstreami++;
return "@";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '<') == 0) {
$lexstreami++;
if (strcmp(substr ($lexstream, $lexstreami, 1), '=') == 0) {
$lexstreami++;
return "<=";
}
return "<";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '>') == 0) {
$lexstreami++;
if (strcmp(substr ($lexstream, $lexstreami, 1), '=') == 0) {
$lexstreami++;
return ">=";
}
return ">";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '=') == 0) {
$lexstreami++;
if (strcmp(substr ($lexstream, $lexstreami, 1), '=') == 0) {
$lexstreami++;
return "==";
}
return "=";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ':') == 0) {
$lexstreami++;
if (strcmp(substr ($lexstream, $lexstreami, 1), '=') == 0) {
$lexstreami++;
return ":=";
}
else
return "NOSIGN";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), '!') == 0) {
$lexstreami++;
if (strcmp(substr ($lexstream, $lexstreami, 1), '=') == 0) {
$lexstreami++;
return "!=";
}
return "!";
}
else if (strcmp(substr ($lexstream, $lexstreami, 1), ' ') == 0) {
$lexstreami++;
return lexer ();
}
else if (is_illegal_sign()) {
return "ILLEGALSIGN";
}
else {
return "NOSIGN";
}
}
function numexpr () {
$x = term ();
$y = numexpr2 ();
return $x+$y;
}
function numexpr2 () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcmp ($op = lexer (), "+") == 0) {
$x = term ();
$y = numexpr2 ();
return $x+$y;
}
if (strcmp ($op, "-") == 0) {
$x = term ();
$y = numexpr2 ();
return -$x+$y;
}
$lexstreami = $lexstreamitmp;
return 0;
}
function term () {
$x = factor ();
$y = term2 ();
return $x*$y;
}
function term2 () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcmp ($op = lexer (), "*") == 0) {
$x = factor ();
$y = term2 ();
return $x*$y;
}
if (strcmp ($op, "/") == 0) {
$x = factor ();
$y = term2 ();
return $y/$x;
}
$lexstreami = $lexstreamitmp;
return 1;
}
function factor () {
global $global_vars;
$retval = lexer ();
$sign = 1;
if (strcmp ($retval, "-") == 0) {
$sign = -1;
$retval = lexer ();
}
else if (strcmp ($retval, "+") == 0) {
$sign = 1;
$retval = lexer ();
}
else
$sign = 1;
if (strcmp (gettype ($retval), "double") == 0) {
return $retval * $sign;
}
else if (strcmp ($retval, '(') == 0) {
$retval = numexpr ();
if (strcmp (lexer (), ")") != 0)
exit ("Forget round bracket in arithmetic expression");
return $retval * $sign;
}
else if (strcmp ($retval, '[') == 0) {
$retval = bnumexpr ();
if (strcmp (lexer (), "]") != 0)
exit ("Forget round bracket in boolean expression");
return $retval;
}
else if (strcasecmp ($retval, "sin") == 0){
$retval = sin(numexpr ()) * $sign;
return $retval;
}
else if (strcasecmp ($retval, "cos") == 0) {
$retval = cos(numexpr ()) * $sign;
return $retval;
}
else if (strcasecmp ($retval, "tan") == 0) {
$retval = tan(numexpr ()) * $sign;
return $retval;
}
else if (strcasecmp ($retval, "exp") == 0) {
$retval = exp(numexpr ()) * $sign;
return $retval;
}
else if (strcasecmp ($retval, "sum") == 0) {
$retval = sum () * $sign;
return $retval;
}
else if (strcmp ($retval, '$') == 0) {
$lx = lexer ();
if ((strcasecmp (substr($lx, 0, 1), "a") >= 0) && (strcasecmp (substr($lx, 0, 1), "z") <= 0)) {
$arraynamestr = arrayname ();
return $global_vars [$lx . $arraynamestr] * $sign;
}
else
exit ("bad variable name");
}
else {
exit ("error in arithmetic expression");
}
}
function bnumexpr () {
$a = bterm ();
$b = bnumexpr2 ();
return $a or $b;
}
function bnumexpr2 () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcmp ($op = lexer (), "or") == 0) {
$a = bterm ();
$b = bnumexpr2 ();
return $a or $b;
}
$lexstreami = $lexstreamitmp;
return false;
}
function bterm () {
$a = bfactor ();
$b = bterm2 ();
return $a and $b;
}
function bterm2 () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcmp ($op = lexer (), "and") == 0) {
$a = bfactor ();
$b = bterm2 ();
return $a and $b;
}
$lexstreami = $lexstreamitmp;
return true;
}
function bfactor () {
global $global_vars;
global $lexstreami;
$lexstreamitmp = $lexstreami;
$retval = lexer ();
if (strcmp ($retval, "false") == 0) {
return false;
}
else if (strcmp ($retval, "true") == 0) {
return true;
}
else if (strcmp ($retval, '[') == 0) {
$retval = bnumexpr ();
if (strcmp (lexer (), "]") != 0)
exit ("Forget round bracket in boolean expression");
return $retval;
}
else if (strcmp ($retval, '(') == 0) {
$x = numexpr ();
$cop = lexer ();
$y = numexpr ();
if (strcmp ($cop, "<") == 0)
$z = ($x < $y);
else if (strcmp ($cop, ">") == 0)
$z = ($x > $y);
else if (strcmp ($cop, "<=") == 0)
$z = ($x <= $y);
else if (strcmp ($cop, ">=") == 0)
$z = ($x >= $y);
else if (strcmp ($cop, "!=") == 0)
$z = ($x != $y);
else if (strcmp ($cop, "==") == 0)
$z = ($x == $y);
else
exit ("Wrong compare operator in boolesche expression");
if (strcmp ($str = lexer (), ")") != 0)
exit ("Forget round bracket in boolean expression");
return $z;
}
else if (strcmp ($retval, '$') == 0) {
$lx = lexer ();
if ((strcasecmp (substr($lx, 0, 1), "a") >= 0) && (strcasecmp (substr($lx, 0, 1), "z") <= 0)) {
$arraynamestr = arrayname ();
return $global_vars [$lx . $arraynamestr];
}
else
exit ("bad variable name");
}
else {
exit ("error in boolean expression");
}
}
function arrayname () {
global $lexstreami;
global $lexstream;
$lexstreamitmp = $lexstreami;
if (strcmp (lexer (), "[") == 0) {
$arrayindexstr = "_" . strval (numexpr());
if (strcmp (lexer (), "]") != 0)
exit ("Forgot closing array bracket");
$lexstreamitmp2 = $lexstreami;
if (strcmp (lexer (), "[") == 0) {
$lexstreami = $lexstreamitmp2;
$arrayindexstr = $arrayindexstr . arrayname ();
}
else
$lexstreami = $lexstreamitmp2;
return $arrayindexstr;
}
$lexstreami = $lexstreamitmp;
return "";
}
function boolexpr () {
$x = numexpr ();
$cop = lexer ();
$y = numexpr ();
if (strcmp ($cop, "<") == 0)
return ($x < $y);
else if (strcmp ($cop, ">") == 0)
return ($x > $y);
else if (strcmp ($cop, "<=") == 0)
return ($x <= $y);
else if (strcmp ($cop, ">=") == 0)
return ($x >= $y);
else if (strcmp ($cop, "!=") == 0)
return ($x != $y);
else if (strcmp ($cop, "==") == 0)
return ($x == $y);
else
exit ("Wrong compare operator in boolesche expression");
}
function block () {
global $lexstreami;
global $lexstream;
$lexstreamitmp = $lexstreami;
if (strcasecmp (lexer (), "begin") == 0) {
statement ();
if (strcasecmp (lexer (), "end") == 0);
else
exit ("forgot end in block");
}
else
exit ("forgot begin in block");
}
function block_do_not_execute () {
$count = 1;
$retstr = "";
if (strcasecmp (lexer (), "begin") == 0) {
while (strcmp ($retstr, "CODEENDS") != 0) {
$retstr = lexer ();
if (strcasecmp ($retstr, "end") == 0)
$count--;
if ($count == 0)
break;
if (strcasecmp ($retstr, "begin") == 0)
$count++;
}
if ($count != 0)
exit ("code ends before block cloesd");
}
else
exit ("forgot begin in block");
}
function loop () {
global $lexstreami;
global $lexstream;
global $loopcount;
$lexstreamitmp = $lexstreami;
if (strcasecmp (lexer (), "while") == 0) {
if (bnumexpr ()) {
if (strcasecmp (lexer (), "do") == 0) {
block ();
$loopcount++;
if ($loopcount > 64)
exit ("you have exceeded the maximum number of loop lengths");
$lexstreami = $lexstreamitmp;
loop ();
return true;
}
else
exit ("Forgot do in while statement");
}
else {
if (strcasecmp (lexer (), "do") == 0) {
block_do_not_execute ();
return true;
}
else
exit ("Forgot do in while statement");
}
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
function statement () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
stmt ();
$lexstreamitmp2 = $lexstreami;
if (strcmp (lexer (), ";") == 0)
statement ();
else
$lexstreami = $lexstreamitmp2;
}
function stmt () {
if (loop ());
else if (assignment ());
else if (cnd ());
else if (ech ());
else if (plot ());
else if (plot_t ());
else if (set_parameter());
}
function sum () {
global $lexstreami;
global $global_vars;
if (isset ($global_vars ["n"]))
$n_tmp = $global_vars ["n"];
$lower = abs(numexpr ());
if (strcasecmp (lexer(), ",") == 0) {
$upper = abs(numexpr ());
if ($lower > $upper)
exit ("sum-Expression can't work - lower limit is greater than upper limit");
if (strcasecmp (lexer(), ",") == 0) {
$lexstreamitmp = $lexstreami;
for ($i = $lower, $z = 0; $i <= $upper; $i++) {
$lexstreami = $lexstreamitmp;
$global_vars ["n"] = $i;
$z = numexpr () + $z;
}
if (isset ($n_tmp))
$global_vars ["n"] = $n_tmp;
$lexstreamitmp2 = $lexstreami;
if (strcasecmp (lexer (), "endsum") == 0);
else
$lexstreami = $lexstreamitmp2;
return $z;
}
else
exit ("forgot comma in sum-Exression");
}
else
exit ("forgot comma in sum-Exression");
}
$flag_image_created;
$flag_interval_limits_initialized;
$myImage;
$trans_colour;
$myBlue;
$myRed;
$plot_varname;
$upper;
$lower;
$flag_interval_limits_initialized_timed;
$myImage_timed;
$trans_colour_timed;
$myBlue_timed;
$myRed_timed;
$plot_varname_timed;
$upper_timed;
$lower_timed;
function create_canvas () {
global $flag_image_created;
global $myImage;
global $trans_colour;
global $myRed;
global $myBlue;
global $upper;
global $lower;
if (!$flag_image_created) {
$myImage = imagecreatetruecolor(800, 600);
$trans_colour = imagecolorallocatealpha($myImage, 127, 127, 255, 0);
imagefill($myImage, 0, 0, $trans_colour);
$myBlue = imagecolorallocate($myImage, 10, 20, 200);
$myRed = imagecolorallocate($myImage, 200, 10, 10);
$flag_image_created = true;
imageline ($myImage, 0-$lower*(800/($upper-$lower))-1, 0, 0-$lower*(800/($upper-$lower))-1, 600, $myRed);;
imageline ($myImage, 0-$lower*(800/($upper-$lower)), 0, 0-$lower*(800/($upper-$lower)), 600, $myRed);;
imageline ($myImage, 0-$lower*(800/($upper-$lower))+1, 0, 0-$lower*(800/($upper-$lower))+1, 600, $myRed);;
imageline ($myImage, 0, 300, 800, 300, $myRed);;
imageline ($myImage, 0, 301, 800, 301, $myRed);;
imageline ($myImage, 0, 299, 800, 299, $myRed);;
}
}
function ends_canvas () {
global $myImage;
global $flag_image_created;
global $animatedplotpngname;
global $compiler_output_str;
global $plot_fname;
if ($flag_image_created) {
ob_start();
imagepng($myImage, $plot_fname);
base64_encode(ob_get_clean());
if ($flag_image_created)
$compiler_output_str = $compiler_output_str . "<img width=\"70%\" src=\"" . $plot_fname . "\">";
}
}
$myImage_timed;
function create_canvas_timed () {
global $flag_image_created_timed;
global $myImage_timed;
global $trans_colour_timed;
global $myRed_timed;
global $myBlue_timed;
global $upper_timed;
global $lower_timed;
$myImage_timed = imagecreatetruecolor(800, 600);
$trans_colour_timed = imagecolorallocatealpha($myImage_timed, 127, 127, 255, 0);
imagefill($myImage_timed, 0, 0, $trans_colour_timed);
$myBlue_timed = imagecolorallocate($myImage_timed, 10, 20, 200);
$myRed_timed = imagecolorallocate($myImage_timed, 200, 10, 10);
imageline ($myImage_timed, 0-$lower_timed*(800/($upper_timed-$lower_timed))-1, 0, 0-$lower_timed*(800/($upper_timed-$lower_timed))-1, 600, $myRed_timed);;
imageline ($myImage_timed, 0-$lower_timed*(800/($upper_timed-$lower_timed)), 0, 0-$lower_timed*(800/($upper_timed-$lower_timed)), 600, $myRed_timed);;
imageline ($myImage_timed, 0-$lower_timed*(800/($upper_timed-$lower_timed))+1, 0, 0-$lower_timed*(800/($upper_timed-$lower_timed))+1, 600, $myRed_timed);;
imageline ($myImage_timed, 0, 300, 800, 300, $myRed_timed);;
imageline ($myImage_timed, 0, 301, 800, 301, $myRed_timed);;
imageline ($myImage_timed, 0, 299, 800, 299, $myRed_timed);;
}
function plot_t () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcasecmp (lexer(), "plotT") == 0) {
plot_timed();
return true;
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
function set_parameter () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcasecmp (lexer(), "SETPARAMETER") == 0) {
set_param ();
return true;
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
function set_param () {
global $lexstreami;
global $plot_timed_interval_length;
global $time_n_count;
$lexstreamitmp = $lexstreami;
if (strcasecmp ($str = lexer(), "PLOTTIMEDINTERVALENGTH") == 0) {
$plot_timed_interval_length = numexpr ();
return true;
}
else if (strcasecmp ($str, "PLOTTIMEDNCOUNT") == 0) {
$time_n_count = numexpr ();
return true;
}
else {
exit ("Wrong Parameter in SET PARAMETER");
}
}
function ends_canvas_timed ($n) {
global $myImage_timed;
global $plot_animated_fname_prefix;
ob_start();
imagepng($myImage_timed, $plot_animated_fname_prefix . str_pad($n, 3, 0, STR_PAD_LEFT) . ".png");
base64_encode(ob_get_clean());
}
function interval_limits1 () {
global $upper;
global $lower;
global $plot_varname;
global $lexstreami;
global $flag_interval_limits_initialized;
$lexstreamitmp = $lexstreami;
numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreamitmp2 = $lexstreami;
numexpr ();
if (lexer () == ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreami = $lexstreamitmp;
$var_name = get_var_name ();
if ($var_name == false)
exit ("Plot: interval limits: Wrong format in variable name");
if (lexer () != ',')
exit ("Plot: interval limits: Wrong format in variable name");
$plot_varname = $var_name;
if (!$flag_interval_limits_initialized) {
$upper = 4.0;
$lower = -4.0;
$flag_interval_limits_initialized = true;
}
$lexstreami = $lexstreamitmp2;
return true;
}
function interval_limits2 () {
global $upper;
global $lower;
global $plot_varname;
global $lexstreami;
global $flag_interval_limits_initialized;
$lexstreamitmp = $lexstreami;
$x = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$y = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreamitmp2 = $lexstreami;
numexpr ();
if (lexer () == ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreami = $lexstreamitmp2;
if (!$flag_interval_limits_initialized) {
$lower = $x;
$upper = $y;
$flag_interval_limits_initialized = true;
}
$plot_varname = "x";
return true;
}
function interval_limits3 () {
global $upper;
global $lower;
global $plot_varname;
global $lexstreami;
global $flag_interval_limits_initialized;
$lexstreamitmp = $lexstreami;
$x = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$y = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreamitmp3 = $lexstreami;
numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreami = $lexstreamitmp3;
$var_name = get_var_name ();
if ($var_name == false)
exit ("Plot: interval limits: Wrong format in variable name");
if (lexer () != ',')
exit ("Plot: interval limits: Wrong format in variable name");
$plot_varname = $var_name;
if (!$flag_interval_limits_initialized) {
$lower = $x;
$upper = $y;
$flag_interval_limits_initialized = true;
}
return true;
}
function interval_limits () {
global $upper;
global $lower;
global $plot_varname;
global $flag_interval_limits_initialized;
if (!interval_limits1 ()) {
if (!interval_limits2 ()) {
if (!interval_limits3 ()) {
if (!$flag_interval_limits_initialized) {
$upper = 4.0;
$lower = -4.0;
}
$plot_varname = "x";
}
}
}
$flag_interval_limits_initialized = true;
}
function plot_timed () {
global $global_vars;
global $lexstreami;
global $plot_timevarname_timed;
global $compiler_output_str;
global $upper_timed;
global $lower_timed;
global $time_n_count;
global $plot_animated_fname_prefix;
$lexstreamitmp = $lexstreami;
interval_limits_timed();
if (isset ($global_vars [$plot_timevarname_timed]))
$tmpt = $global_vars [$plot_timevarname_timed];
for ($t = $lower_timed, $i = 0; $t < $upper_timed; $t += (($upper_timed-$lower_timed)/$time_n_count), $i++) {
$lexstreami = $lexstreamitmp;
create_canvas_timed ();
$global_vars [$plot_timevarname_timed] = $t;
plot_real_timed ();
ends_canvas_timed ($i);
}
if (isset ($tmpt));
$global_vars [$plot_timevarname_timed] = $tmpt;
$compiler_output_str = $compiler_output_str . "<img id=\"anime\" src=\"" . $plot_animated_fname_prefix . str_pad(0, 3, 0, STR_PAD_LEFT) . ".png\">";
}
function get_var_name () {
global $lexstreami;
global $lexstream;
$lexstreamitmp = $lexstreami;
if (lexer () != '$') {
$lexstreami = $lexstreamitmp;
return false;
}
$retval = lexer ();
if (!(strcasecmp (substr ($retval, 0, 1), "a") >= 0) && (strcasecmp (substr ($retval, 0, 1), "z") <= 0))
$retval = false;
return $retval;
}
function interval_limits1_timed () {
global $upper_timed;
global $lower_timed;
global $plot_varname_timed;
global $lexstreami;
global $flag_interval_limits_initialized_timed;
$lexstreamitmp = $lexstreami;
numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreamitmp2 = $lexstreami;
numexpr ();
if (lexer () == ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreami = $lexstreamitmp;
$var_name = get_var_name ();
if ($var_name == false)
exit ("Plot: interval limits: Wrong format in variable name");
if (lexer () != ',')
exit ("Plot: interval limits: Wrong format in variable name");
$plot_varname_timed = $var_name;
if (!$flag_interval_limits_initialized_timed) {
$upper_timed = 4.0;
$lower_timed = -4.0;
$flag_interval_limits_initialized_timed = true;
}
$lexstreami = $lexstreamitmp2;
return true;
}
function interval_limits2_timed () {
global $upper_timed;
global $lower_timed;
global $plot_varname_timed;
global $lexstreami;
global $flag_interval_limits_initialized_timed;
$lexstreamitmp = $lexstreami;
$x = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$y = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreamitmp2 = $lexstreami;
numexpr ();
if (lexer () == ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreami = $lexstreamitmp2;
if (!$flag_interval_limits_initialized_timed) {
$lower_timed = $x;
$upper_timed = $y;
$flag_interval_limits_initialized_timed = true;
}
$plot_varname_timed = "x";
return true;
}
function interval_limits3_timed () {
global $upper_timed;
global $lower_timed;
global $plot_varname_timed;
global $lexstreami;
global $flag_interval_limits_initialized_timed;
$lexstreamitmp = $lexstreami;
$x = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$y = numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreamitmp3 = $lexstreami;
numexpr ();
if (lexer () != ',') {
$lexstreami = $lexstreamitmp;
return false;
}
$lexstreami = $lexstreamitmp3;
$var_name = get_var_name ();
if ($var_name == false)
exit ("Plot: interval limits: Wrong format in variable name");
if (lexer () != ',')
exit ("Plot: interval limits: Wrong format in variable name");
$plot_varname_timed = $var_name;
if (!$flag_interval_limits_initialized_timed) {
$lower_timed = $x;
$upper_timed = $y;
$flag_interval_limits_initialized_timed = true;
}
return true;
}
function interval_limits_timed () {
global $upper_timed;
global $lower_timed;
global $plot_varname_timed;
global $flag_interval_limits_initialized_timed;
if (!interval_limits1_timed ()) {
if (!interval_limits2_timed ()) {
if (!interval_limits3_timed ()) {
if (!$flag_interval_limits_initialized_timed) {
$upper_timed = 4.0;
$lower_timed = -4.0;
}
$plot_varname_timed = "x";
}
}
}
$flag_interval_limits_initialized_timed = true;
}
function plot_real () {
global $lexstreami;
global $global_vars;
global $myImage;
global $trans_colour;
global $myRed;
global $myBlue;
global $upper;
global $lower;
global $plot_varname;
interval_limits ();
$lexstreamitmp = $lexstreami;
if (isset ($global_vars [$plot_varname]))
$tmpx = $global_vars [$plot_varname];
$v = $lower;
$global_vars [$plot_varname] = $v;
$max = numexpr ();
for ($v = $lower+(($upper-$lower)/800); $v < $upper; $v += (($upper-$lower)/800)) {
$lexstreami = $lexstreamitmp;
$global_vars [$plot_varname] = $v;
if(($t = numexpr ()) > $max)
$max = $t;
}
create_canvas ();
$lexstreami = $lexstreamitmp;
$v = $lower;
$global_vars [$plot_varname] = $v;
$oldt = numexpr ();
$oldt = $oldt / $max;
$oldt = $t * 300 + 300;
$oldti = ceil ($oldt);
for ($v = $lower+(($upper-$lower)/800), $j = 0; $v < $upper; $v += (($upper-$lower)/800), $j++) {
$lexstreami = $lexstreamitmp;
$global_vars [$plot_varname] = $v;
$t = numexpr ();
$t = $t / $max;
$t = $t * 300 + 300;
$ti = ceil ($t);
imageline ($myImage, $j, 600-$oldti, $j+1, 600-$ti, $myBlue);;
imageline ($myImage, $j, 600-$oldti-1, $j+1, 600-$ti-1, $myBlue);;
imageline ($myImage, $j, 600-$oldti-2, $j+1, 600-$ti-2, $myBlue);;
$oldt = $t;
$oldti = ceil ($oldt);
}
if (isset ($tmpx));
$global_vars [$plot_varname] = $tmpx;
}
function plot_real_timed () {
global $lexstreami;
global $global_vars;
global $myImage_timed;
global $trans_colour_timed;
global $myRed_timed;
global $myBlue_timed;
global $plot_varname_timed;
global $upper_timed;
global $lower_timed;
global $plot_timevarname_timed;
global $tmpx;
interval_limits_timed();
$lexstreamitmp = $lexstreami;
if (isset ($global_vars [$plot_varname_timed]))
$tmpx = $global_vars [$plot_varname_timed];
if (isset ($global_vars [$plot_timevarname_timed]))
$tmpt = $global_vars [$plot_timevarname_timed];
$v = $lower_timed;
$global_vars [$plot_varname_timed] = $v;
$max = numexpr ();
for ($v = $lower_timed+(($upper_timed-$lower_timed)/800); $v < $upper_timed; $v += (($upper_timed-$lower_timed)/800)) {
$lexstreami = $lexstreamitmp;
$global_vars [$plot_varname_timed] = $v;
if(($t = numexpr ()) > $max)
$max = $t;
}
create_canvas ();
$lexstreami = $lexstreamitmp;
$v = $lower_timed;
$global_vars [$plot_varname_timed] = $v;
$oldt = numexpr ();
$oldt = $oldt / $max;
$oldt = $t * 300 + 300;
$oldti = ceil ($oldt);
for ($v = $lower_timed+(($upper_timed-$lower_timed)/800), $j = 0; $v < $upper_timed; $v += (($upper_timed-$lower_timed)/800), $j++) {
$lexstreami = $lexstreamitmp;
$global_vars [$plot_varname_timed] = $v;
$t = numexpr ();
$t = $t / $max;
$t = $t * 300 + 300;
$ti = ceil ($t);
imageline ($myImage_timed, $j, 600-$oldti, $j+1, 600-$ti, $myBlue_timed);;
imageline ($myImage_timed, $j, 600-$oldti-1, $j+1, 600-$ti-1, $myBlue_timed);;
imageline ($myImage_timed, $j, 600-$oldti-2, $j+1, 600-$ti-2, $myBlue_timed);;
$oldt = $t;
$oldti = ceil ($oldt);
}
if (isset ($tmpx));
$global_vars [$plot_varname_timed] = $tmpx;
if (isset ($tmpt));
$global_vars [$plot_timevarname_timed] = $tmpt;
}
function plot () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcasecmp (lexer(), "plot") == 0) {
plot_real();
return true;
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
function ech () {
global $lexstreami;
global $compiler_output_str;
$lexstreamitmp = $lexstreami;
if (strcasecmp (lexer(), "echo") == 0) {
$compiler_output_str = $compiler_output_str . numexpr () . "<br>";
return true;
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
function assignment () {
global $lexstreami;
global $global_vars;
$lexstreamitmp = $lexstreami;
if (strcmp (lexer (), '$') == 0) {
$lx = lexer ();
if ((strcasecmp (substr($lx, 0, 1), "a") >= 0) && (strcasecmp (substr($lx, 0, 1), "z") <= 0))
$arraynamestr = arrayname ();
else
exit ("bad variable name");
if (strcmp (lexer (), ":=") == 0) {
$global_vars [$lx . $arraynamestr] = numexpr ();
return true;
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
function cnd () {
global $lexstreami;
$lexstreamitmp = $lexstreami;
if (strcasecmp (lexer (), "if") == 0) {
$flag = bnumexpr ();
if (strcasecmp (lexer (), "then") == 0) {
if ($flag) {
block ();
$lexstreamitmp2 = $lexstreami;
if (strcasecmp (lexer (), "else") == 0) {
block_do_not_execute ();
}
else
$lexstreami = $lexstreamitmp2;
return true;
}
else {
block_do_not_execute ();
$lexstreamitmp2 = $lexstreami;
if (strcasecmp (lexer (), "else") == 0)
block ();
else
$lexstreami = $lexstreamitmp2;
return true;
}
}
else
exit ("Forget then in if-Statement");
}
else {
$lexstreami = $lexstreamitmp;
return false;
}
}
function plot_animate_create_output_str () {
global $compiler_output_str;
global $time_n_count;
global $plot_timed_interval_length;
global $plot_animated_fname_prefix;
$compiler_output_str = $compiler_output_str . "<script>var i = 1; setInterval (doachange, " .$plot_timed_interval_length . " ); function doachange () {document.getElementById(\"anime\").src= \"" .$plot_animated_fname_prefix . "\" + str_pad(i, 3, 0, STR_PAD_LEFT) + \".png\";i = (i+1) % ". $time_n_count ." ;}</script>";
}
if ($flg) {
exec ("convert -delay 20 -loop 0 *.png animatedcompiler.gif");
exec ("python3 compilertwitterimage2.py");
echo "Hallo";
}
?>