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('*')); }
private function compareToStackTop(Operator $operator) { $top = $this->operatorStack->top(); if ($top === null) { return false; } if ($this->binaryOperators->exists($operator) && $operator === $top) { if ($operator->isAssociativity(Operator::LEFT)) { return true; } if ($operator->isAssociativity(Operator::RIGHT)) { return false; } //e.g. (5 is divisible by 2 is divisible by 3) is not considered valid $symbols = $operator->operators(); if (is_array($symbols)) { $symbols = implode(', ', $symbols); } throw new ParseException("Binary operator '{$symbols}' is not associative", $this->stream->current()->getLine()); } return $top->getPrecedence() >= $operator->getPrecedence(); }