Overview

Namespaces

  • BN
    • Collections
    • Compiler
      • Grammar
      • Parser
        • Operator
        • Token
      • Postfix
        • Operands
        • Operator
        • Token
      • Scanner
        • Converter
      • Token
  • Demo
  • None

Classes

  • AssignOperator
  • CallbackEvaluator

Interfaces

  • OperatorEvaluator
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace BN\Compiler\Postfix\Operator;
 4: 
 5: use BN\Compiler\Postfix\Variables;
 6: use BN\Compiler\Token\Token;
 7: use BN\Compiler\Token\TokenType;
 8: 
 9: class AssignOperator
10: {
11:     private $variables;
12: 
13:     public function __construct(Variables $variables)
14:     {
15:         $this->variables = $variables;
16:     }
17: 
18:     public function __invoke(array $tokens)
19:     {
20:         $a = array_shift($tokens);
21:         $b = array_shift($tokens);
22:         return $this->evaluate($a, $b);
23:     }
24: 
25:     public function evaluate(Token $a, Token $b)
26:     {
27:         if ($a->type == TokenType::VARIABLE) {
28:             $value = $this->variables->exists($b) ? $this->variables->get($b) : $b->value;
29:             $this->variables->set($a, $value);
30:             return $value;
31:         } else {
32:             return null;
33:         }
34:     }
35: }
36: 
BN-PHP - Big Number data type for PHP API documentation generated by ApiGen 2.8.0