formats.mathparser - ICE 0.1 API documentation

ICE 0.1 API documentation

# 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:

  expression | Math expression to parse.
  substitutions | Substitutions to use.

  Returns:
  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:

  input | String to apply substitutions to.
  substitutions | Dictionary of substitutions to apply.

  Returns:
  Input string with substitutions applied.
T parsePostfix(T)(const string postfix);

  Parse a postfix math expression and return its result.

  Parameters:

  postfix | Postfix expression to parse.

  Returns:
  Result of the expression.
  Throws:
  MathParsetException if an invalid token is detected in the expression.

Copyright © Ferdinand Majerech 2011. | Page generated by AutoDDoc and Ddoc.