1: <?php
2:
3: namespace BN\Compiler\Postfix\Operands;
4:
5: use BN\Collections\Stack;
6:
7: abstract class Operands
8: {
9: protected $operandsCount;
10:
11: public function __construct($operandsCount)
12: {
13: $this->operandsCount = $operandsCount;
14: }
15:
16: public function getOperands(Stack $stack)
17: {
18: $r = new OperandsSummary();
19: $r->operands = $this->getOperandsInInfixOrder($stack);
20: $r->areOperandsValid = $this->isOperandsCountValid($r->countOperands());
21: $r->expectedCount = $this->operandsCount;
22: return $r;
23: }
24:
25: private function getOperandsInInfixOrder(Stack $stack)
26: {
27: $operands = $this->popOperands($stack);
28: return array_reverse($operands);
29: }
30:
31: abstract protected function popOperands(Stack $stack);
32:
33: abstract protected function isOperandsCountValid($operandsCount);
34: }
35: