98 'sin',
'sinh',
'arcsin',
'asin',
'arcsinh',
'asinh',
99 'cos',
'cosh',
'arccos',
'acos',
'arccosh',
'acosh',
100 'tan',
'tanh',
'arctan',
'atan',
'arctanh',
'atanh',
101 'sqrt',
'abs',
'ln',
'log');
106 $this->v[
'pi'] = pi();
107 $this->v[
'exp'] = exp(1);
109 $this->v[
'e'] = exp(1);
120 $expr = preg_replace_callback(
121 "/(\\d{0,1})e(-{0,1}\\d+)/is",
123 return $hit[1].((strlen($hit[1])) ?
'*' :
'').
'10^('.$hit[2].
')';
128 $this->last_error = null;
130 if (substr($expr, -1, 1) ==
';') $expr = substr($expr, 0, strlen($expr)-1);
133 if (preg_match(
'/^\s*([a-z]\w*)\s*=\s*(.+)$/', $expr, $matches)) {
134 if (in_array($matches[1], $this->vb)) {
135 return $this->
trigger(
"cannot assign to constant '$matches[1]'");
137 if (($tmp = $this->
pfx($this->
nfx($matches[2]))) ===
false)
return false;
138 $this->v[$matches[1]] = $tmp;
139 return $this->v[$matches[1]];
142 } elseif (preg_match(
'/^\s*([a-z]\w*)\s*\(\s*([a-z]\w*(?:\s*,\s*[a-z]\w*)*)\s*\)\s*=\s*(.+)$/', $expr, $matches)) {
144 if (in_array($matches[1], $this->fb)) {
145 return $this->
trigger(
"cannot redefine built-in function '$matches[1]()'");
147 $args = explode(
",", preg_replace(
"/\s+/",
"", $matches[2]));
148 if (($stack = $this->
nfx($matches[3])) ===
false)
return false;
149 for ($i = 0; $i<count($stack); $i++) {
151 if (preg_match(
'/^[a-z]\w*$/', $token)
and !in_array($token, $args)) {
152 if (array_key_exists($token, $this->v)) {
153 $stack[$i] = $this->v[$token];
155 return $this->
trigger(
"undefined variable '$token' in function definition");
159 $this->f[$fnn] =
array(
'args'=>$args,
'func'=>$stack);
163 return $this->
pfx($this->
nfx($expr));
176 foreach ($this->f as $fnn=>$dat)
177 $output[] = $fnn .
'(' . implode(
',', $dat[
'args']) .
')';
189 $expr = trim(strtolower($expr));
191 $ops =
array(
'+',
'-',
'*',
'/',
'^',
'_');
192 $ops_r =
array(
'+'=>0,
'-'=>0,
'*'=>0,
'/'=>0,
'^'=>1);
193 $ops_p =
array(
'+'=>0,
'-'=>0,
'*'=>1,
'/'=>1,
'_'=>1,
'^'=>2);
195 $expecting_op =
false;
198 if (preg_match(
"/[^\w\s+*^\/()\.,-]/", $expr, $matches)) {
199 return $this->
trigger(
"illegal character '{$matches[0]}'");
203 $op = substr($expr, $index, 1);
205 $ex = preg_match(
'/^([01]+[bB]|[\da-fA-F]+[hH]|[a-z]\w*\(?|\d+(?:\.\d*)?|\.\d+|\()/', substr($expr, $index), $match);
207 if ($op ==
'-' and !$expecting_op) {
210 } elseif ($op ==
'_') {
211 return $this->
trigger(
"illegal character '_'");
213 } elseif ((in_array($op, $ops)
or $ex)
and $expecting_op) {
218 while($stack->count > 0
and ($o2 = $stack->last())
and in_array($o2, $ops)
and ($ops_r[$op] ? $ops_p[$op] < $ops_p[$o2] : $ops_p[$op] <= $ops_p[$o2])) {
224 $expecting_op =
false;
226 } elseif ($op ==
')' and $expecting_op) {
227 while (($o2 = $stack->pop()) !=
'(') {
228 if (is_null($o2))
return $this->
trigger(
"unexpected ')'");
231 if (preg_match(
"/^([a-z]\w*)\($/", $stack->last(2), $matches)) {
233 $arg_count = $stack->pop();
235 if (in_array($fnn, $this->fb)) {
237 return $this->
trigger(
"too many arguments ($arg_count given, 1 expected)");
238 } elseif (array_key_exists($fnn, $this->f)) {
239 if ($arg_count != count($this->f[$fnn][
'args']))
240 return $this->
trigger(
"wrong number of arguments ($arg_count given, " . count($this->f[$fnn][
'args']) .
" expected)");
242 return $this->
trigger(
"internal error");
247 } elseif ($op ==
',' and $expecting_op) {
248 while (($o2 = $stack->pop()) !=
'(') {
249 if (is_null($o2))
return $this->
trigger(
"unexpected ','");
253 if (!preg_match(
"/^([a-z]\w*)\($/", $stack->last(2), $matches))
254 return $this->
trigger(
"unexpected ','");
255 $stack->push($stack->pop()+1);
258 $expecting_op =
false;
260 } elseif ($op ==
'(' and !$expecting_op) {
265 } elseif ($ex
and !$expecting_op) {
266 $expecting_op =
true;
268 if (preg_match(
"/^([a-z]\w*)\($/", $val, $matches)) {
269 if (in_array($matches[1], $this->fb)
or array_key_exists($matches[1], $this->f)) {
273 $expecting_op =
false;
281 $index += strlen($val);
283 } elseif ($op ==
')') {
284 return $this->
trigger(
"unexpected ')'");
285 } elseif (in_array($op, $ops)
and !$expecting_op) {
286 return $this->
trigger(
"unexpected operator '$op'");
288 return $this->
trigger(
"an unexpected error occured");
290 if ($index == strlen($expr)) {
291 if (in_array($op, $ops)) {
292 return $this->
trigger(
"operator '$op' lacks operand");
297 while (substr($expr, $index, 1) ==
' ') {
302 while (!is_null($op = $stack->pop())) {
303 if ($op ==
'(')
return $this->
trigger(
"expecting ')'");
312 if ($tokens ==
false)
return false;
316 foreach ($tokens as $token) {
318 if (in_array($token,
array(
'+',
'-',
'*',
'/',
'^'))) {
319 if (is_null($op2 = $stack->pop()))
return $this->
trigger(
"internal error");
320 if (is_null($op1 = $stack->pop()))
return $this->
trigger(
"internal error");
321 include_once
"class.ilMath.php";
330 if ($op2 == 0)
return $this->
trigger(
"division by zero");
336 } elseif ($token ==
"_") {
337 $stack->push(-1*$stack->pop());
339 } elseif (preg_match(
"/^([a-z]\w*)\($/", $token, $matches)) {
341 if (in_array($fnn, $this->fb)) {
342 if (is_null($op1 = $stack->pop()))
return $this->
trigger(
"internal error");
343 $fnn = preg_replace(
"/^arc/",
"a", $fnn);
346 } elseif ($fnn ==
'ln') {
350 $stack->push($fnn($op1));
351 } elseif (array_key_exists($fnn, $this->f)) {
354 for ($i = count($this->f[$fnn][
'args'])-1; $i >= 0; $i--) {
355 if (is_null($args[$this->f[$fnn][
'args'][$i]] = $stack->pop()))
return $this->
trigger(
"internal error");
357 $stack->push($this->
pfx($this->f[$fnn][
'func'], $args));
361 if (is_numeric($token)) {
362 $stack->push($token);
363 } elseif (($hex=$this->
from_hexbin($token))!==FALSE) {
365 } elseif (array_key_exists($token, $this->v)) {
366 $stack->push($this->v[$token]);
367 } elseif (array_key_exists($token, $vars)) {
368 $stack->push($vars[$token]);
370 return $this->
trigger(
"undefined variable '$token'");
375 if ($stack->count != 1)
return $this->
trigger(
"internal error");
376 return $stack->pop();
381 $this->last_error = $msg;
382 if (!$this->suppress_errors) trigger_error($msg, E_USER_WARNING);
389 if (strtoupper(substr($token, -1, 1))==
'H')
return hexdec($token);
390 if (strtoupper(substr($token, -1, 1))==
'B')
return bindec($token);
402 $this->stack[$this->count] = $val;
407 if ($this->count > 0) {
409 return $this->stack[$this->count];
416 if(isset($this->stack[$this->count-
$n])) {
417 return $this->stack[$this->count -
$n];
static _div($left_operand, $right_operand, $scale=50)
static _pow($left_operand, $right_operand, $scale=50)
static _add($left_operand, $right_operand, $scale=50)
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
pfx($tokens, $vars=array())
Create styles array
The data for the language used.
static _mul($left_operand, $right_operand, $scale=50)
static _sub($left_operand, $right_operand, $scale=50)