Example #1
0
 /**
  * Parse the expression.
  *
  * @param int $precedence The precedence level.
  * @return Node The expression node.
  */
 private function parseExpression($precedence)
 {
     /* @var Token $token */
     $node = $this->parsePrimary();
     while (($token = $this->stream->current()) && $this->operatorTable->isBinary($token)) {
         $operator = $this->operatorTable->getBinaryOperator($token);
         if ($operator->getPrecedence() < $precedence) {
             break;
         }
         $this->stream->next();
         $operatorNode = $operator->getNode();
         $node = $operatorNode($node, $this->parseExpression($operator->isRightAssociative() ? $operator->getPrecedence() : $operator->getPrecedence() + 1));
     }
     $node = $this->parseTernary($node, $precedence);
     return $node;
 }
Example #2
0
 /**
  * Test if the `getBinaryOperator` method throws an exception if the requested operator doesn't exists.
  *
  * @expectedException \com\mohiva\pyramid\exceptions\UnsupportedOperatorException
  */
 public function testGetBinaryOperatorThrowsException()
 {
     $token = new Token(1, '+', 1);
     $table = new OperatorTable();
     $table->getBinaryOperator($token);
 }