Index: trunk/extensions/ParserFunctions/Expr.php |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | define( 'EXPR_GREATEREQ', 19 ); |
32 | 32 | define( 'EXPR_NOTEQ', 20 ); |
33 | 33 | define( 'EXPR_ROUND', 21 ); |
| 34 | +define( 'EXPR_EXPONENT', 22 ); |
34 | 35 | |
35 | 36 | class ExprError extends Exception { |
36 | 37 | public function __construct($msg, $parameter = ''){ |
— | — | @@ -44,6 +45,7 @@ |
45 | 46 | var $precedence = array( |
46 | 47 | EXPR_NEGATIVE => 10, |
47 | 48 | EXPR_POSITIVE => 10, |
| 49 | + EXPR_EXPONENT => 9, |
48 | 50 | EXPR_NOT => 9, |
49 | 51 | EXPR_TIMES => 8, |
50 | 52 | EXPR_DIVIDE => 8, |
— | — | @@ -60,7 +62,7 @@ |
61 | 63 | EXPR_AND => 3, |
62 | 64 | EXPR_OR => 2, |
63 | 65 | EXPR_OPEN => -1, |
64 | | - EXPR_CLOSE => -1 |
| 66 | + EXPR_CLOSE => -1, |
65 | 67 | ); |
66 | 68 | |
67 | 69 | var $names = array( |
— | — | @@ -81,6 +83,7 @@ |
82 | 84 | EXPR_NOTEQ => '<>', |
83 | 85 | EXPR_AND => 'and', |
84 | 86 | EXPR_OR => 'or', |
| 87 | + EXPR_EXPONENT => 'e', |
85 | 88 | ); |
86 | 89 | |
87 | 90 | |
— | — | @@ -90,7 +93,8 @@ |
91 | 94 | 'or' => EXPR_OR, |
92 | 95 | 'not' => EXPR_NOT, |
93 | 96 | 'round' => EXPR_ROUND, |
94 | | - 'div' => EXPR_DIVIDE |
| 97 | + 'div' => EXPR_DIVIDE, |
| 98 | + 'e' => EXPR_EXPONENT, |
95 | 99 | ); |
96 | 100 | |
97 | 101 | /** |
— | — | @@ -187,7 +191,7 @@ |
188 | 192 | } |
189 | 193 | |
190 | 194 | // Finally the single-character operators |
191 | | - |
| 195 | + |
192 | 196 | elseif ( $char == '+' ) { |
193 | 197 | ++$p; |
194 | 198 | if ( $expecting == 'expression' ) { |
— | — | @@ -382,6 +386,12 @@ |
383 | 387 | $left = array_pop( $stack ); |
384 | 388 | $stack[] = ( $left != $right ) ? 1 : 0; |
385 | 389 | break; |
| 390 | + case EXPR_EXPONENT: |
| 391 | + if ( count( $stack ) < 2 ) throw new ExprError('missing_operand', $this->names[$op]); |
| 392 | + $right = array_pop( $stack ); |
| 393 | + $left = array_pop( $stack ); |
| 394 | + $stack[] = $left * pow(10,$right); |
| 395 | + break; |
386 | 396 | default: |
387 | 397 | // Should be impossible to reach here. |
388 | 398 | throw new ExprError('unknown_error'); |