@@ 23-35 (lines=13) @@ | ||
20 | */ |
|
21 | namespace SimpleMath\Expressions; |
|
22 | ||
23 | abstract class Comparison extends Operator { |
|
24 | ||
25 | protected $precidence = 3; |
|
26 | ||
27 | public function operate(\SimpleMath\Stack $stack, $variables=array()) |
|
28 | { |
|
29 | $right = $stack->pop()->operate($stack, $variables); |
|
30 | $left = $stack->pop()->operate($stack, $variables); |
|
31 | return $this->cmp($left, $right) ? 1 : 0; |
|
32 | } |
|
33 | ||
34 | abstract protected function cmp($left, $right); |
|
35 | } |
|
36 |
@@ 23-33 (lines=11) @@ | ||
20 | */ |
|
21 | namespace SimpleMath\Expressions; |
|
22 | ||
23 | class Division extends Operator { |
|
24 | ||
25 | protected $precidence = 5; |
|
26 | ||
27 | public function operate(\SimpleMath\Stack $stack, $variables=array()) { |
|
28 | $left = $stack->pop()->operate($stack, $variables); |
|
29 | $right = $stack->pop()->operate($stack, $variables); |
|
30 | return $right / $left; |
|
31 | } |
|
32 | ||
33 | } |
|
34 |
@@ 23-33 (lines=11) @@ | ||
20 | */ |
|
21 | namespace SimpleMath\Expressions; |
|
22 | ||
23 | class Modulo extends Operator { |
|
24 | ||
25 | protected $precidence = 5; |
|
26 | ||
27 | public function operate(\SimpleMath\Stack $stack, $variables=array()) { |
|
28 | $left = $stack->pop()->operate($stack, $variables); |
|
29 | $right = $stack->pop()->operate($stack, $variables); |
|
30 | return $right % $left; |
|
31 | } |
|
32 | ||
33 | } |
|
34 |