|
@@ 2195-2213 (lines=19) @@
|
| 2192 |
|
* |
| 2193 |
|
* @return \Doctrine\ORM\Query\AST\SimpleArithmeticExpression |
| 2194 |
|
*/ |
| 2195 |
|
public function SimpleArithmeticExpression() { |
| 2196 |
|
$terms = array(); |
| 2197 |
|
$terms[] = $this->ArithmeticTerm(); |
| 2198 |
|
|
| 2199 |
|
while (($isPlus = $this->lexer->isNextToken(Lexer::T_PLUS)) || $this->lexer->isNextToken(Lexer::T_MINUS)) { |
| 2200 |
|
$this->match(($isPlus) ? Lexer::T_PLUS : Lexer::T_MINUS); |
| 2201 |
|
|
| 2202 |
|
$terms[] = $this->lexer->token['value']; |
| 2203 |
|
$terms[] = $this->ArithmeticTerm(); |
| 2204 |
|
} |
| 2205 |
|
|
| 2206 |
|
// Phase 1 AST optimization: Prevent AST\SimpleArithmeticExpression |
| 2207 |
|
// if only one AST\ArithmeticTerm is defined |
| 2208 |
|
if (count($terms) == 1) { |
| 2209 |
|
return $terms[0]; |
| 2210 |
|
} |
| 2211 |
|
|
| 2212 |
|
return new AST\SimpleArithmeticExpression($terms); |
| 2213 |
|
} |
| 2214 |
|
|
| 2215 |
|
/** |
| 2216 |
|
* ArithmeticTerm ::= ArithmeticFactor {("*" | "/") ArithmeticFactor}* |
|
@@ 2220-2238 (lines=19) @@
|
| 2217 |
|
* |
| 2218 |
|
* @return \Doctrine\ORM\Query\AST\ArithmeticTerm |
| 2219 |
|
*/ |
| 2220 |
|
public function ArithmeticTerm() { |
| 2221 |
|
$factors = array(); |
| 2222 |
|
$factors[] = $this->ArithmeticFactor(); |
| 2223 |
|
|
| 2224 |
|
while (($isMult = $this->lexer->isNextToken(Lexer::T_MULTIPLY)) || $this->lexer->isNextToken(Lexer::T_DIVIDE)) { |
| 2225 |
|
$this->match(($isMult) ? Lexer::T_MULTIPLY : Lexer::T_DIVIDE); |
| 2226 |
|
|
| 2227 |
|
$factors[] = $this->lexer->token['value']; |
| 2228 |
|
$factors[] = $this->ArithmeticFactor(); |
| 2229 |
|
} |
| 2230 |
|
|
| 2231 |
|
// Phase 1 AST optimization: Prevent AST\ArithmeticTerm |
| 2232 |
|
// if only one AST\ArithmeticFactor is defined |
| 2233 |
|
if (count($factors) == 1) { |
| 2234 |
|
return $factors[0]; |
| 2235 |
|
} |
| 2236 |
|
|
| 2237 |
|
return new AST\ArithmeticTerm($factors); |
| 2238 |
|
} |
| 2239 |
|
|
| 2240 |
|
/** |
| 2241 |
|
* ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary |