formats.mathparser
Math expression parser.
- class MathParserException: object.Exception;
Exception thrown at math parsing errors.
- T parseMath(T)(const string expression, T[string] substitutions = null);
Parse a string as a math expression.
An associative array of substitutions can be passed to substitute strings in the expression for numbers. Substitutions are not checked for operators or spaces, so it is possible to e.g. substitute "abc * d" for 42 .
Parameters:Returns:expression Math expression to parse. substitutions Substitutions to use. Result of the expression.Throws:MathParserException if the expression is invalid (e.g. parentheses mismatch or redundant operator)- void unittestParseMath();
Unittest for parseMath
- string substitute(T)(const string input, T[string] substitutions);
Substitute strings for numbers based on a dictionary.
Parameters:Returns:input String to apply substitutions to. substitutions Dictionary of substitutions to apply. Input string with substitutions applied.- T parsePostfix(T)(const string postfix);
Parse a postfix math expression and return its result.
Parameters:Returns:postfix Postfix expression to parse. Result of the expression.Throws:MathParsetException if an invalid token is detected in the expression.