1: <?php
2:
3: namespace BN\Compiler\Postfix\Token;
4:
5: use BN\Compiler\Token\Token;
6: use BN\Compiler\Postfix\ProcessToken;
7:
8: class ProcessConstant extends ProcessToken
9: {
10: private $constants;
11:
12: public function __construct($accumulator, array $constants)
13: {
14: $this->accumulator = $accumulator;
15: $this->constants = $constants;
16: }
17:
18: public function process(Token $token)
19: {
20: $constant = $token->value;
21: if (array_key_exists($constant, $this->constants)) {
22: $value = $this->constants[$constant];
23: $this->accumulator->pushNumber($value);
24: } else {
25: $this->accumulator->stopCalculation('undefinedVariable', $constant);
26: }
27: }
28: }
29: