MediaWiki REL1_30
ExprParser Class Reference

Public Member Functions

 doExpression ( $expr)
 Evaluate a mathematical expression.
 
 doOperation ( $op, &$stack)
 

Public Attributes

 $maxStackSize = 100
 
 $names
 
 $precedence
 
 $words
 

Detailed Description

Definition at line 69 of file Expr.php.

Member Function Documentation

◆ doExpression()

ExprParser::doExpression ( $expr)

Evaluate a mathematical expression.

The algorithm here is based on the infix to RPN algorithm given in http://montcs.bloomu.edu/~bobmon/Information/RPN/infix2rpn.shtml It's essentially the same as Dijkstra's shunting yard algorithm.

Parameters
$exprstring
Exceptions
ExprError
Returns
string

Definition at line 183 of file Expr.php.

References $matches, doOperation(), EXPR_ABS, EXPR_ARCCOS, EXPR_ARCSINE, EXPR_ARCTAN, EXPR_CEIL, EXPR_COSINE, EXPR_DIVIDE, EXPR_EQUALITY, EXPR_EXP, EXPR_EXPONENT, EXPR_FLOOR, EXPR_GREATER, EXPR_GREATEREQ, EXPR_LESS, EXPR_LESSEQ, EXPR_LN, EXPR_MINUS, EXPR_NEGATIVE, EXPR_NOT, EXPR_NOTEQ, EXPR_NUMBER_CLASS, EXPR_OPEN, EXPR_PI, EXPR_PLUS, EXPR_POSITIVE, EXPR_POW, EXPR_SINE, EXPR_SQRT, EXPR_TANGENS, EXPR_TIMES, EXPR_TRUNC, and EXPR_WHITE_CLASS.

◆ doOperation()

Member Data Documentation

◆ $maxStackSize

ExprParser::$maxStackSize = 100

Definition at line 70 of file Expr.php.

◆ $names

ExprParser::$names

Definition at line 111 of file Expr.php.

◆ $precedence

ExprParser::$precedence

Definition at line 72 of file Expr.php.

◆ $words

ExprParser::$words
Initial value:
= [
'mod' => EXPR_MOD,
'fmod' => EXPR_FMOD,
'and' => EXPR_AND,
'or' => EXPR_OR,
'not' => EXPR_NOT,
'round' => EXPR_ROUND,
'div' => EXPR_DIVIDE,
'e' => EXPR_EXPONENT,
'sin' => EXPR_SINE,
'cos' => EXPR_COSINE,
'tan' => EXPR_TANGENS,
'asin' => EXPR_ARCSINE,
'acos' => EXPR_ARCCOS,
'atan' => EXPR_ARCTAN,
'exp' => EXPR_EXP,
'ln' => EXPR_LN,
'abs' => EXPR_ABS,
'trunc' => EXPR_TRUNC,
'floor' => EXPR_FLOOR,
'ceil' => EXPR_CEIL,
'pi' => EXPR_PI,
'sqrt' => EXPR_SQRT,
]
const EXPR_COSINE
Definition Expr.php:37
const EXPR_AND
Definition Expr.php:25
const EXPR_TANGENS
Definition Expr.php:38
const EXPR_EXP
Definition Expr.php:42
const EXPR_ARCSINE
Definition Expr.php:39
const EXPR_EXPONENT
Definition Expr.php:35
const EXPR_PI
Definition Expr.php:49
const EXPR_DIVIDE
Definition Expr.php:21
const EXPR_ARCCOS
Definition Expr.php:40
const EXPR_OR
Definition Expr.php:26
const EXPR_ARCTAN
Definition Expr.php:41
const EXPR_FLOOR
Definition Expr.php:45
const EXPR_SQRT
Definition Expr.php:51
const EXPR_LN
Definition Expr.php:43
const EXPR_SINE
Definition Expr.php:36
const EXPR_FMOD
Definition Expr.php:50
const EXPR_TRUNC
Definition Expr.php:46
const EXPR_ABS
Definition Expr.php:44
const EXPR_NOT
Definition Expr.php:27
const EXPR_MOD
Definition Expr.php:22
const EXPR_ROUND
Definition Expr.php:34
const EXPR_CEIL
Definition Expr.php:47

Definition at line 148 of file Expr.php.


The documentation for this class was generated from the following file: