Ejemplo n.º 1
0
 public function __construct(int $line, string $name)
 {
     parent::__construct($line);
     if (false === array_search($name, VARIABLES, true)) {
         throw new \UnexpectedValueException("'{$name}' is not one of the defined variables: " . var_export(VARIABLES, true));
     }
     $this->name = $name;
 }
Ejemplo n.º 2
0
 public function __construct(int $line, string $kind, Node $left, Node $right)
 {
     parent::__construct($line);
     if (!isset(OPERATORS[$kind])) {
         throw new \UnexpectedValueException("'{$kind}' is not one of the accepted operator types: " . var_export(array_keys(OPERATORS), true));
     }
     $this->kind = $kind;
     $this->left = $left;
     $this->right = $right;
 }
Ejemplo n.º 3
0
 public function __construct(int $line, string $name, array $arguments)
 {
     parent::__construct($line);
     if (!isset(FUNCTIONS[$name])) {
         throw new \UnexpectedValueException("'{$name}' is not one of the accepted functions: " . var_export(array_keys(FUNCTIONS), true));
     }
     $functionData = FUNCTIONS[$name];
     if (count($arguments) !== $functionData['arity']) {
         throw new \RangeException("'{$name}' has an arity of {$functionData['arity']}, but " . count($arguments) . " arguments given");
     }
     foreach ($arguments as $i => $argument) {
         if (!$argument instanceof Node) {
             throw new \UnexpectedValueException("Argument {$i} is not " . Node::class);
         }
     }
     $this->name = $name;
     $this->arguments = $arguments;
 }