-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTerminalExpression.php
More file actions
84 lines (73 loc) · 2.08 KB
/
TerminalExpression.php
File metadata and controls
84 lines (73 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* The PHP Math Parser library
*
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace PHPMathParser;
use PHPMathParser\Expressions\Addition;
use PHPMathParser\Expressions\Division;
use PHPMathParser\Expressions\Multiplication;
use PHPMathParser\Expressions\Number;
use PHPMathParser\Expressions\Parenthesis;
use PHPMathParser\Expressions\Power;
use PHPMathParser\Expressions\Subtraction;
use PHPMathParser\Expressions\Unary;
use PHPMathParser\Expressions\MathFunction;
abstract class TerminalExpression
{
protected $value = '';
public function __construct($value)
{
$this->value = $value;
}
public static function factory($value)
{
if (is_object($value) && $value instanceof self) {
return $value;
} elseif (is_numeric($value)) {
return new Number($value);
} elseif ($value == 'u') {
return new Unary($value);
} elseif ($value == '+') {
return new Addition($value);
} elseif ($value == '-') {
return new Subtraction($value);
} elseif ($value == '*') {
return new Multiplication($value);
} elseif ($value == '/') {
return new Division($value);
} elseif (in_array($value, array('(', ')'))) {
return new Parenthesis($value);
} elseif ($value == '^') {
return new Power($value);
} elseif (MathFunction::isFunction($value)) {
return new MathFunction($value);
}
throw new \Exception('Undefined Value ' . $value);
}
abstract public function operate(Stack $stack);
public function isOperator()
{
return false;
}
public function isUnary()
{
return false;
}
public function isParenthesis()
{
return false;
}
public function isNoOp()
{
return false;
}
public function render()
{
return $this->value;
}
}