public function testOperatorsAreReturnedBySymbol() { $this->assertTrue($this->collection->exists($this->mockOperator)); $this->assertTrue($this->collection->exists($this->otherOperator)); $this->assertFalse($this->collection->exists($this->getMockBuilder('\\Minty\\Compiler\\Operator')->disableOriginalConstructor()->getMockForAbstractClass())); $this->assertSame($this->mockOperator, $this->collection->getOperator('+')); $this->assertSame($this->mockOperator, $this->collection->getOperator('-')); $this->assertSame($this->otherOperator, $this->collection->getOperator('*')); }
/** * @param bool $return * * @return Node|null */ private function parseExpression($return = false) { //push sentinel $this->operatorStack->push(null); $token = $this->parseToken(); while ($token->test(Token::OPERATOR, [$this->binaryOperators, 'isOperator'])) { $this->pushOperator($this->binaryOperators->getOperator($token->getValue())); $token = $this->parseToken(); } while ($this->operatorStack->top() !== null) { $this->popOperator(); } //pop sentinel $this->operatorStack->pop(); //A conditional is marked by '?' (punctuation, not operator) so it breaks the loop above. if ($token->test(Token::PUNCTUATION, '?')) { $this->parseConditional(); } if ($return) { return $this->operandStack->pop(); } return null; }