Example #1
0
 /**
  * Parse primary expression.
  *
  * @return Node The primary node.
  * @throws SyntaxErrorException if no operand or unary operator can be found.
  */
 private function parsePrimary()
 {
     /* @var Token $token */
     $token = $this->stream->current();
     if ($token && $this->operatorTable->isUnary($token)) {
         $this->stream->next();
         $operator = $this->operatorTable->getUnaryOperator($token);
         $operatorNode = $operator->getNode();
         $node = $operatorNode($this->parseExpression($operator->getPrecedence()));
     } else {
         if ($token) {
             $node = $this->parseOperand();
             $this->stream->next();
         } else {
             throw new SyntaxErrorException('Operand or unary operator expected; but end of stream reached');
         }
     }
     return $node;
 }
Example #2
0
 /**
  * Test if the `isUnary` method returns false if the given token isn't an unary operator.
  */
 public function testIsUnaryReturnsFalse()
 {
     $operator = new BinaryOperator(1, 10, BinaryOperator::LEFT, function () {
     });
     $token = new Token($operator->getCode(), '+', 1);
     $table = new OperatorTable();
     $table->addOperator($operator);
     $this->assertFalse($table->isUnary($token));
 }