Пример #1
0
 /**
  * Evaluate a VariableNode
  *
  * Returns the current value of a VariableNode, as defined
  * either by the constructor or set using the `Evaluator::setVariables()` method.
  * @see Evaluator::setVariables() to define the variables
  * @throws UnknownVariableException if the variable respresented by the
  *      VariableNode is *not* set.
  *
  * @param VariableNode $node AST to be evaluated
  * @retval float
  */
 public function visitVariableNode(VariableNode $node)
 {
     $name = $node->getName();
     if (array_key_exists($name, $this->variables)) {
         return $this->variables[$name];
     }
     throw new UnknownVariableException($name);
 }
Пример #2
0
 /**
  * Print a VariableNode.
  *
  * @param VariableNode $node
  */
 public function visitVariableNode(VariableNode $node)
 {
     return $node->getName();
 }
Пример #3
0
 /**
  * Differentiate a VariableNode
  *
  * Create a NumberNode representing '0' or '1' depending on
  * the differetiation variable.
  *
  * @param NumberNode $node AST to be differentiated
  * @retval Node
  */
 public function visitVariableNode(VariableNode $node)
 {
     if ($node->getName() == $this->variable) {
         return new IntegerNode(1);
     }
     return new IntegerNode(0);
 }