MediaWiki REL1_34
MediaWiki\Extensions\ParserFunctions\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 71 of file ExprParser.php.

Member Function Documentation

◆ doExpression()

MediaWiki\Extensions\ParserFunctions\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
string$expr
Exceptions
ExprError
Returns
string

Definition at line 185 of file ExprParser.php.

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

◆ doOperation()

MediaWiki\Extensions\ParserFunctions\ExprParser::doOperation ( $op,
& $stack )
Parameters
int$op
array&$stack
Exceptions
ExprError

Definition at line 402 of file ExprParser.php.

References MediaWiki\Extensions\ParserFunctions\EXPR_ABS, MediaWiki\Extensions\ParserFunctions\EXPR_AND, MediaWiki\Extensions\ParserFunctions\EXPR_ARCCOS, MediaWiki\Extensions\ParserFunctions\EXPR_ARCSINE, MediaWiki\Extensions\ParserFunctions\EXPR_ARCTAN, MediaWiki\Extensions\ParserFunctions\EXPR_CEIL, MediaWiki\Extensions\ParserFunctions\EXPR_COSINE, MediaWiki\Extensions\ParserFunctions\EXPR_DIVIDE, MediaWiki\Extensions\ParserFunctions\EXPR_EQUALITY, MediaWiki\Extensions\ParserFunctions\EXPR_EXP, MediaWiki\Extensions\ParserFunctions\EXPR_EXPONENT, MediaWiki\Extensions\ParserFunctions\EXPR_FLOOR, MediaWiki\Extensions\ParserFunctions\EXPR_FMOD, MediaWiki\Extensions\ParserFunctions\EXPR_GREATER, MediaWiki\Extensions\ParserFunctions\EXPR_GREATEREQ, MediaWiki\Extensions\ParserFunctions\EXPR_LESS, MediaWiki\Extensions\ParserFunctions\EXPR_LESSEQ, MediaWiki\Extensions\ParserFunctions\EXPR_LN, MediaWiki\Extensions\ParserFunctions\EXPR_MINUS, MediaWiki\Extensions\ParserFunctions\EXPR_MOD, MediaWiki\Extensions\ParserFunctions\EXPR_NEGATIVE, MediaWiki\Extensions\ParserFunctions\EXPR_NOT, MediaWiki\Extensions\ParserFunctions\EXPR_NOTEQ, MediaWiki\Extensions\ParserFunctions\EXPR_OR, MediaWiki\Extensions\ParserFunctions\EXPR_PLUS, MediaWiki\Extensions\ParserFunctions\EXPR_POSITIVE, MediaWiki\Extensions\ParserFunctions\EXPR_POW, MediaWiki\Extensions\ParserFunctions\EXPR_ROUND, MediaWiki\Extensions\ParserFunctions\EXPR_SINE, MediaWiki\Extensions\ParserFunctions\EXPR_SQRT, MediaWiki\Extensions\ParserFunctions\EXPR_TANGENS, MediaWiki\Extensions\ParserFunctions\EXPR_TIMES, and MediaWiki\Extensions\ParserFunctions\EXPR_TRUNC.

Referenced by MediaWiki\Extensions\ParserFunctions\ExprParser\doExpression().

Member Data Documentation

◆ $maxStackSize

MediaWiki\Extensions\ParserFunctions\ExprParser::$maxStackSize = 100

Definition at line 72 of file ExprParser.php.

◆ $names

MediaWiki\Extensions\ParserFunctions\ExprParser::$names

Definition at line 113 of file ExprParser.php.

◆ $precedence

MediaWiki\Extensions\ParserFunctions\ExprParser::$precedence

Definition at line 74 of file ExprParser.php.

◆ $words

MediaWiki\Extensions\ParserFunctions\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,
]

Definition at line 150 of file ExprParser.php.


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