1: <?php
2:
3: namespace BN\Compiler\Postfix\Token;
4:
5: use BN\Compiler\Token\Token;
6: use BN\Compiler\Postfix\ProcessToken;
7: use BN\Compiler\Grammar\Operators;
8: use BN\Compiler\Postfix\Variables;
9:
10: class ProcessOperator extends ProcessToken implements ProcessKeywordStrategy
11: {
12: private $operators;
13: private $operatorSymbol;
14: private $processKeyword;
15:
16: public function __construct($accumulator, Operators $operators, Variables $variables)
17: {
18: $this->accumulator = $accumulator;
19: $this->operators = $operators;
20: $this->processKeyword = new ProcessKeyword($accumulator, $variables, $this);
21: }
22:
23: public function process(Token $token)
24: {
25: $this->operatorSymbol = $token->value;
26: if ($this->operators->exists($this->operatorSymbol)) {
27: $this->processKeyword->process($token);
28: } else {
29: $this->accumulator->stopCalculation('unknownOperator', $this->operatorSymbol);
30: }
31: }
32:
33: public function isFirstOperandVariable()
34: {
35: return false;
36: }
37:
38: public function getOperands()
39: {
40: return $this->operators->getOperands($this->operatorSymbol);
41: }
42:
43: public function tokensToOperands(array $tokens)
44: {
45: $operands = array();
46: foreach ($tokens as $token) {
47: $operands[] = $token->value;
48: }
49: return $operands;
50: }
51:
52: public function getEvaluator()
53: {
54: return $this->operators->getEvaluator($this->operatorSymbol);
55: }
56: }
57: