bcParserObjC  1.1
Math Parser for Objective C, iOS and OSX
 All Classes Functions Variables Properties Pages
Instance Methods | Protected Attributes | Properties | List of all members
MathParser Class Reference

MathParser class provides the capability to parse and evaluate math expressions given as strings at runtime. More...

Inheritance diagram for MathParser:

Instance Methods

(void) - parse
 Parses the mathematical expression to form a tree of Node objects to be evaluated when evaluate function is called or value property is accessed. More...
 
(double) - evaluate
 Evaluates and returns the value of the expression. More...
 
(BOOL) - isVariableUsed:
 Returns true if a variable with the name 'varName' is used in the current expression. More...
 
(BOOL) - isFunctionUsed:
 Returns true if a function with the name 'funcName' is used in the current expression. More...
 
(BOOL) - isVariable:
 Returns true if a variable with the name 'varName' is present in the current variables list. More...
 
(BOOL) - isConstant:
 Returns true if a constant with the name 'constName' is defined.
 
(BOOL) - isFunction:
 Returns true if a function with the name 'funcName' is present in any of the current functions lists. More...
 
(void) - setVariable:withNewValue:maybeConstant:
 Variable property is a way to set and get variable values. More...
 
(void) - setVariable:withNewValue:
 Variable property is a way to set and get variable values. More...
 
(void) - createConstant:withValue:
 Creates a new constant that can be used in an expression. More...
 
(void) - createFunc:withImpl:
 createFunc method creates a new function that takes n number of parameters (could be 0) in the parser's list of functions. More...
 
(void) - createDefaultFuncs
 createDefaultFuncs method creates some predefined functions in the parser's list of functions. More...
 
(void) - deleteVar:
 DeleteVar method deletes an existing variable from the list of available variables. More...
 
(void) - deleteFunc:
 deleteFunc method deletes an existing function from the list of available functions. More...
 
(void) - deleteAllVars
 deleteAllVars method deletes all variables from the list of available variables. More...
 
(void) - deleteAllFuncs
 deleteAllFuncs method deletes all variables from the list of available functions. More...
 
(void) - optimize
 Optimizes the parse tree by finding branches that evaluate to a constant and replacing them with a leaf representing the constant. More...
 
(NSArray *) - getVariables
 Returns an NSArray that contains variable names as NSString* that the MathParser instance knows about. More...
 
(NSArray *) - getFunctions
 Returns an NSArray that contains function names as NSString* that the MathParser instance knows about. More...
 
(NSArray *) - getVariablesUsed
 Returns the list of variables used in the current expression as an array of Strings. More...
 
(void) - FreeParseTree
 FreeParseTree can be explicitly called to free the resources taken by the allocated Parse tree when an expression is parsed. More...
 

Protected Attributes

NSString * m_Expression
 protected variable that holds the expression to parse.
 
BOOL m_Dirty
 non-public flag that shows if parsing is needed or not. More...
 
BOOL m_OptimizationOn
 when optimization on, after the parse tree is compiled, it will be further optimized by removing sub branches that evaluate to a constant. More...
 
NSObject< Node > * m_Node
 Starting node for the internal compiled representation of the expression in parsed form. More...
 
NSMutableDictionary * m_Variables
 internal list of variables that are available for use in an expression.
 
NSMutableDictionary * m_Functions
 internal list of functions that take more than 2 parameters that are available for use in an expression.
 
NSLocale * m_Locale
 
BOOL m_LocaleSpecificDecimals
 
NSObject< VariableDelegate > * m_VariableDelegate
 
char m_DecimalSeperatorChar
 
NSString * m_DecimalSeparatorStr
 
char m_FunctionParamSeparatorChar
 
NSString * m_FunctionParamSeparatorStr
 

Properties

NSString * expression
 Expression property represents the mathematical expression which is input to be Evaluated by the user. More...
 
double value
 Invokes evaluate method and returns the calculated value for the given expression. More...
 
BOOL precedingZerosAllowed
 Is 05 a valid number or not? By default it is not. If this property is set to true, then it is valid.
 
NSLocale * locale
 Locale to use for uppercasing and decimal separator (point or comma) if localeSpecificDecimals is true. More...
 
BOOL localeSpecificDecimals
 If true, locale specific decimal separator will be used. More...
 
NSObject< VariableDelegate > * variableDelegate
 VariableDelegate is used as a callback function that returns the values of variables when asked. More...
 
NSDictionary * translationStrings
 Returns the existing translatable strings used to report error messages. More...
 
BOOL optimizationOn
 Should the parser optimize constant expressions? For example 3+1 will be optimized to 4 to benefit repeated evaluations. More...
 

Detailed Description

MathParser class provides the capability to parse and evaluate math expressions given as strings at runtime.

MathParser class calculates the value of mathematical expressions given as strings at runtime.

The expression can contain built-in or user defined variables and functions. Common math functions are already defined for every parser instance.

In order to parse an expression you need to set the expression property to a string that contains a math expression like: "X/Y+SIN(X-Y)". You also need to set the values for X and Y variables using setVariable method. Alternatively you can assign a variableDelegate. Then you get the value of value property, or you can call evaluate method.

Expression can contain predefined or user defined variables and functions.

Method Documentation

- (void) createConstant: (NSString *)  varName
withValue: (double)  newVal 

Creates a new constant that can be used in an expression.

Once a constant is created, it's value cannot be changed. Constants make it possible to optimize constant branches of an expression.

- (void) createDefaultFuncs

createDefaultFuncs method creates some predefined functions in the parser's list of functions.



Predefined functions are:

SQR: Square function which can be used as SQR(X)

SIN: Sinus function which can be used as SIN(X), X is a real-type expression. Sin returns the sine of the angle X in radians.

COS: Cosinus function which can be used as COS(X), X is a real-type expression. COS returns the cosine of the angle X in radians.

ATAN: ArcTangent function which can be used as ATAN(X)

SINH: Sinus Hyperbolic function which can be used as SINH(X)

COSH: Cosinus Hyperbolic function which can be used as COSH(X)

COTAN: which can be used as COTAN(X)

TAN: which can be used as TAN(X)

EXP: which can be used as EXP(X)

LN: natural log, which can be used as LN(X)

LOG: 10 based log, which can be used as LOG(X)

SQRT: which can be used as SQRT(X)

ABS: absolute value, which can be used as ABS(X)

SIGN: SIGN(X) returns -1 if X<0; +1 if X>0, 0 if X=0; it can be used as SQR(X)

TRUNC: Discards the fractional part of a number. e.g. TRUNC(-3.2) is -3, TRUNC(3.2) is 3.

CEIL: CEIL(-3.2) = 3, CEIL(3.2) = 4

FLOOR: FLOOR(-3.2) = -4, FLOOR(3.2) = 3

VAL: VAL("3.1") = 3.1 Returns the floating point numeric value of the string argument.

Predefined functions that take two parameters are:

INTPOW: The INTPOW function raises Base to an integral power. INTPOW(2, 3) = 8. Note that result of INTPOW(2, 3.4) = 8 as well.

POW: The Power function raises Base to any power. For fractional exponents or exponents greater than MaxInt, Base must be greater than 0.

LOGN: The LogN function returns the log base N of X. Example: LOGN(10, 100) = 2

MIN: MIN(2, 3) is 2.

MAX: MAX(2, 3) is 3.

IF: The IF(b, case1, case2) function provides branching capability. If b is not 0, then it returns case1, else it returns case2. Behavior is similar to C#'s: return b ? case1 : case2;
If b==0 then case1 will not be Evaluated, and vice versa. Example: IF(HEIGHT, 3/HEIGHT, 3) will make sure 3/HEIGHT does not cause division by zero.

Predefined functions that take no parameters are: RND: RND() function generates a random number (double value) between 0 and 1.

SUM: SUM(2,3,5,...) function returns the sum of it's arguments. There is no preset limit on the number of parameters.

Functions and Variables can be deleted using deleteVar, deleteFunc, deleteAllVars, deleteAllFuncs methods.

- (void) createFunc: (NSString *)  newFuncName
withImpl: (NSObject<Function> *)  funcAddr 

createFunc method creates a new function that takes n number of parameters (could be 0) in the parser's list of functions.

If the function name already exists then this method throws Exception. Function name is not case sensitive.

The second parameter is an object that implements Function protocol.

While evaluation of the expression, when the registered function name is encountered, the user supplied run: (Function-p) will be called.

This event handler will need to return a result (representing the value of the function) based on the parameters passed as an array of Parameter objects. If the number of parameters that a function takes is not known ahead of time, then the getNumberOfParameters function needs to return -1. Otherwise, it will return the number of parameters that will be passed to the function at runtime. Knowing the number of parameters ahead of time helps detect syntax errors during parsing. For example, if SIN(x) function descriptor did not tell us that it was taking only 1 parameter, then an expression like: SIN(x,y) would not cause syntax error during parsing, and if the implementation of SIN(x) did not check actual runtime number of parameters passed, then the problem could go undetected and the second y parameter could be ignored silently.

- (void) deleteAllFuncs

deleteAllFuncs method deletes all variables from the list of available functions.



This action may be useful when number of unused functions is too high that causes performance to degrade.

When a function is deleted Dirty flag is set to true so that next time the Evaluate function is called the expression will be reparsed.

- (void) deleteAllVars

deleteAllVars method deletes all variables from the list of available variables.



This action may be useful when number of unused variables is too high that causes performance to degrade.

When a variable is deleted Dirty flag is set to true so that next time the Evaluate function is called the expression will be reparsed.

- (void) deleteFunc: (NSString *)  funcName

deleteFunc method deletes an existing function from the list of available functions.

If the function does not exist, deleteFunc does nothing.

When a function is deleted Dirty flag is set to true so that next time the Evaluate function is called the expression will be reparsed. Function name is not case sensitive.

Parameters
funcNameName of the function to delete.
- (void) deleteVar: (NSString *)  varName

DeleteVar method deletes an existing variable from the list of available variables.

deleteVar method deletes an existing variable from the list of available variables.

If the variable does not exist, then DeleteVar does nothing.

When a variable is deleted Dirty flag is set to true so that next time the Evaluate function is called the expression will be reparsed. Variable name is not case sensitive.

Parameters
varNameName of the variable to delete.
- (double) evaluate

Evaluates and returns the value of the expression.

Evaluates the expression and returns the result of it.

If the expression needs parsing parse method called. Most syntax errors are caught and reported during parse operation. If a variableDelegate is registered it will be called during evaluate execution. If variableDelegate throws an exception, it will be thrown from the evaluate method.

See Also
- parse method for details about parsing related considerations.

If it cannot be parsed or evaluated then this method throws Exception.

Calling this method is identical to calling getValue() <return>Returns the value of the parsed expression. The return type is an IConvertible that can be interpreted as either Double or String using the Convert class.</return>

- (void) FreeParseTree

FreeParseTree can be explicitly called to free the resources taken by the allocated Parse tree when an expression is parsed.

FreeParseTree sets the Dirty flag to true so that next time the Evaluate function is called, expression will be parsed forming a new, valid parse tree to be evaluated.

- (NSArray *) getFunctions

Returns an NSArray that contains function names as NSString* that the MathParser instance knows about.

Returns a NSString array of function names declared for this parser.

Elements of the array are guaranteed not to be null.

- (NSArray *) getVariables

Returns an NSArray that contains variable names as NSString* that the MathParser instance knows about.

Returns the list of variables as an array of NSStrings.

Each element of the array is guaranteed not to be null.

- (NSArray *) getVariablesUsed

Returns the list of variables used in the current expression as an array of Strings.

Returns the list of variables used in the current expression as an array of NSStrings.

Each element of the array is guaranteed not to be null. If variables are not defined ahead of time, then variableDelegate must have been set. Otherwise, when an undefined variable is found in the expression, ParserException will be thrown.

Each element of the array is guaranteed not to be null. If variables are not defined ahead of time, then VariableDelegate must have been set. Otherwise, when an undefined variable is found in the expression, ParserException will be thrown.

- (BOOL) isFunction: (NSString *)  funcName

Returns true if a function with the name 'funcName' is present in any of the current functions lists.

- (BOOL) isFunctionUsed: (NSString *)  funcName

Returns true if a function with the name 'funcName' is used in the current expression.

Function name is not case sensitive. Throws exception if expression is not parsed and cannot be parsed.

- (BOOL) isVariable: (NSString *)  varName

Returns true if a variable with the name 'varName' is present in the current variables list.

For backward compatibility, IsVariable returns true for constants also. For constants, you can use IsConstant.

- (BOOL) isVariableUsed: (NSString *)  varName

Returns true if a variable with the name 'varName' is used in the current expression.

Variable name is not case sensitive. Throws exception if expression is not parsed and cannot be parsed.

- (void) optimize

Optimizes the parse tree by finding branches that evaluate to a constant and replacing them with a leaf representing the constant.

Until the expression is changed and reparsed, further evaluation requests will be quicker.

If the same expression will not be evaluated repeatedly with varying values of parameters used in it, then optimization will not bring any gain, but will slow performance.

If OptimizationOn property is set to true, this method is called automatically when an evaluation is requested by calling evaluate method or value property.

Until the expression is changed and reparsed, further evaluation requests will be quicker.

If the same expression will not be evaluated repeatedly with varying values of parameters used in it, then optimization will not bring any gain, but will slow performance.

If OptimizationOn property is set to true, this method is called automatically when an evaluation is requested by calling Evaluate method or getValue() method.

- (void) parse

Parses the mathematical expression to form a tree of Node objects to be evaluated when evaluate function is called or value property is accessed.

Parses the expression and forms a parse tree.

Most syntax errors are caught and reported during parse operation. If a variableDelegate is registered it will be called during evaluate execution, not parse. Prior to calling parse, either a proper variableDelegate must be set or variables that are used in the expression must have been registered via setVariable method or createConstant method. Functions that are used in the expression must have been registered via createFunc method. Parse can be used to check the basic syntax of the expression. Usually to get the value of an expression evaluate method can be called which calls parse only if it is needed (Only when something was changed since the last parse operation). If opetimizationOn property is set, the resulting Node tree will be optimized to replace constant branches with a simply constant value. For example X+3+5 will be converted to X+8. This way repeated evaluations for different variable values need recompute 3+5 repeatedly.

Throws Exception if it cannot parse. Upon successful completion of parsing, it will set the Dirty flag to false, so that unless the expression is changed or variables and functions added or removed, expression does not need to be re-parsed. Users may want to call the parse method directly to check the validity of an input expression using a try-except block.

If OptimizationOn property is true, Parse method will optimize the parse tree by evaluating constant branches of the parse tree at that moment, so that Evaluate function will run faster.

- (void) setVariable: (NSString *)  varName
withNewValue: (double)  newVal 

Variable property is a way to set and get variable values.

SetVariable function creates the variable if the variable does not exist. Variable name is not case sensitive. Throws exception if the variable needs to be created and the name is not a valid variable name.

SetVariable function creates the variable if the variable does not exist. Variable name is not case sensitive. Throws exception if the variable needs to be created and the name is not a valid variable name. CreateVar is just an alias for this method.

Parameters
newValNew value of the variable. It should be either a Double or a String.
varNameName of the variable whose value is being set.
- (void) setVariable: (NSString *)  varName
withNewValue: (double)  newVal
maybeConstant: (bool)  isConst 

Variable property is a way to set and get variable values.

SetVariable function creates the variable if the variable does not exist. Variable name is not case sensitive. Throws exception if the variable needs to be created and the name is not a valid variable name. Parameters: varName: Name of the variable whose value is being set. newVal: New value of the variable. isConst: Is this a constant value such as PI?.

SetVariable function creates the variable if the variable does not exist. Variable name is not case sensitive. Throws exception if the variable needs to be created and the name is not a valid variable name. CreateVar is just an alias for this method.

Parameters
newValNew value of the variable. It should be either a Double or a String.
varNameName of the variable whose value is being set.
isConstIs this a constant value such as PI?.
valueProviderThe callback delegate that decides the value of the variable at runtime.

public delegate IConvertible VariableDelegate(MathParser parser, String varName);

Member Data Documentation

- (BOOL) m_Dirty
protected

non-public flag that shows if parsing is needed or not.

if false, existing parse tree will be re-used.

- (NSObject<Node>*) m_Node
protected

Starting node for the internal compiled representation of the expression in parsed form.

- (BOOL) m_OptimizationOn
protected

when optimization on, after the parse tree is compiled, it will be further optimized by removing sub branches that evaluate to a constant.

This will make Parse() operation slower and GetValue() operation faster.

Property Documentation

- (NSString *) expression
readwritenonatomicassign

Expression property represents the mathematical expression which is input to be Evaluated by the user.

The expression can contain variables and/or constants such as X, Y, T, HEIGHT, WEIGHT and so on. The values of these constants are set before the expression is evaluated. The values of the variables can be set before the expression is evaluated or the values can be provided during evaluation using a VariableDelegate.

Expression can also contain functions that take any number of parameters. Variable and Function names are not case sensitive.

When Expression is assigned a value, it becomes 'dirty' and further attempt to Evaluate its value will require it to be Parsed. But once it is Parsed, and a Parse tree representing the expression is formed, it won't be Parsed again, until it is assignd a new string (or another relevant change occurs). Instead, the Parse tree will be used to retrieve current results as the values of variables change.

X, Y and PI variables are predefined and can be immediately used in the expression. CreateVar, SetVariable methods can be used to add user variables.

Predefined functions are:

SQR: Square function which can be used as SQR(X)

SIN: Sinus function which can be used as SIN(X), X is a real-type expression. Sin returns the sine of the angle X in radians.

COS: Cosinus function which can be used as COS(X), X is a real-type expression. COS returns the cosine of the angle X in radians.

ATAN: ArcTangent function which can be used as ATAN(X)

SINH: Sinus Hyperbolic function which can be used as SINH(X)

COSH: Cosinus Hyperbolic function which can be used as COSH(X)

COTAN: which can be used as COTAN(X)

TAN: which can be used as TAN(X)

EXP: which can be used as EXP(X)

LN: natural log, which can be used as LN(X)

LOG: 10 based log, which can be used as LOG(X)

SQRT: which can be used as SQRT(X)

ABS: absolute value, which can be used as ABS(X)

SIGN: SIGN(X) returns -1 if X<0; +1 if X>0, 0 if X=0; it can be used as SQR(X)

TRUNC: Discards the fractional part of a number. e.g. TRUNC(-3.2) is -3, TRUNC(3.2) is 3.

CEIL: CEIL(-3.2) = 3, CEIL(3.2) = 4

FLOOR: FLOOR(-3.2) = -4, FLOOR(3.2) = 3

Predefined functions that take two parameters are:

INTPOW: The INTPOW function raises Base to an integral power. INTPOW(2, 3) = 8. Note that result of INTPOW(2, 3.4) = 8 as well.

POW: The Power function raises Base to any power. For fractional exponents or exponents greater than MaxInt, Base must be greater than 0.

LOGN: The LogN function returns the log base N of X. Example: LOGN(10, 100) = 2

MIN: MIN(2, 3) is 2.

MAX: MAX(2, 3) is 3.

IF: The IF(b, case1, case2) function provides branching capability. If b is not 0, then it returns case1, else it returns case2. Behavior is similar to C#'s: return b ? case1 : case2;
If b==0 then case1 will not be Evaluated, and vice versa. Example: IF(HEIGHT, 3/HEIGHT, 3) will make sure 3/HEIGHT does not cause division by zero.

Predefined functions that take no parameters are: RND: RND() function generates a random number (double value) between 0 and 1.

SUM: SUM(2,3,5,...) functions returns the sum of it's arguments. There is no preset limit on the number of parameters.

User functions can be added using createFunc method. Functions and Variables can be deleted using deleteVar, deleteFunc, deleteAllVars, deleteAllFuncs methods.

The expression can contain variables and/or constants such as X, Y, T, HEIGHT, WEIGHT and so on. The values of these constants are set before the expression is evaluated. The values of the variables can be set before the expression is evaluated or the values can be provided during evaluation using a delegate ValueProvider.



public delegate IConvertible VariableDelegate(MathParser parser, String varName);

Expression can also contain functions that take any number of parameters. Variable and Function names are not case sensitive.

When Expression is assigned a value, it becomes 'dirty' and further attempt to Evaluate its value will require it to be Parsed. But once it is Parsed, and a Parse tree representing the expression is formed, it won't be Parsed again, until it is assignd a new string (or another relevant change occurs). Instead, the Parse tree will be used to retrieve current results as the values of variables change.

X, Y and PI variables are predefined and can be immediately used in the expression. CreateVar, SetVariable methods can be used to add user variables.

Predefined functions are:

SQR: Square function which can be used as SQR(X)

SIN: Sinus function which can be used as SIN(X), X is a real-type expression. Sin returns the sine of the angle X in radians.

COS: Cosinus function which can be used as COS(X), X is a real-type expression. COS returns the cosine of the angle X in radians.

ATAN: ArcTangent function which can be used as ATAN(X)

SINH: Sinus Hyperbolic function which can be used as SINH(X)

COSH: Cosinus Hyperbolic function which can be used as COSH(X)

COTAN: which can be used as COTAN(X)

TAN: which can be used as TAN(X)

EXP: which can be used as EXP(X)

LN: natural log, which can be used as LN(X)

LOG: 10 based log, which can be used as LOG(X)

SQRT: which can be used as SQRT(X)

ABS: absolute value, which can be used as ABS(X)

SIGN: SIGN(X) returns -1 if X<0; +1 if X>0, 0 if X=0; it can be used as SQR(X)

TRUNC: Discards the fractional part of a number. e.g. TRUNC(-3.2) is -3, TRUNC(3.2) is 3.

CEIL: CEIL(-3.2) = 3, CEIL(3.2) = 4

FLOOR: FLOOR(-3.2) = -4, FLOOR(3.2) = 3

Predefined functions that take two parameters are:

INTPOW: The INTPOW function raises Base to an integral power. INTPOW(2, 3) = 8. Note that result of INTPOW(2, 3.4) = 8 as well.

POW: The Power function raises Base to any power. For fractional exponents or exponents greater than MaxInt, Base must be greater than 0.

LOGN: The LogN function returns the log base N of X. Example: LOGN(10, 100) = 2

MIN: MIN(2, 3) is 2.

MAX: MAX(2, 3) is 3.

IF: The IF(b, case1, case2) function provides branching capability. If b is not 0, then it returns case1, else it returns case2. Behavior is similar to C#'s: return b ? case1 : case2;
If b==0 then case1 will not be Evaluated, and vice versa. Example: IF(HEIGHT, 3/HEIGHT, 3) will make sure 3/HEIGHT does not cause division by zero.

Predefined functions that take no parameters are: RND: RND() function generates a random number (double value) between 0 and 1.

STR: STR(123) function returns the string representation of the passed value: "123".

SUBSTR: SUBSTR("Hello", 1,3) function returns the substring just like C# String.Substring function. The first parameter is the string, the second parameter is which index (0 based) to start copying, and the last parameter is the number of characters to copy. For example, SUBSTR("Hello", 1,3) returns "ell".

STRLEN: STRLEN("abc") function returns the length of the string parameter. For example, for "abc" it returns 3.

CONCAT: CONCAT("abc","def",...) function returns the concatanated strings: "abcdef". There is no preset limit on the number of parameters.

SUM: SUM(2,3,5,...) functions returns the sum of it's arguments. There is no preset limit on the number of parameters.

User functions can be added using CreateFunc method. Functions and Variables can be deleted using DeleteVar, DeleteFunc, DeleteAllVars, DeleteAllFuncs methods.

- (NSLocale *) locale
readwritenonatomicassign

Locale to use for uppercasing and decimal separator (point or comma) if localeSpecificDecimals is true.

If set, locale impacts uppercasing the expression.

If localeSpecificDecimals is true, locale also decides the decimal separator to use [dot (.) vs comma (,)]. If comma is used, function parameters are separated by colon (:)

- (BOOL) localeSpecificDecimals
readwritenonatomicassign

If true, locale specific decimal separator will be used.

If true, then decimal separator will be decided based on locale property.

In the US decimal seperator is dot (.) where as in Europe decimal separartor is comma (,). When European decimal seperator is in effect, function parameter separator will be colon (:). If you don't want to use colon as function parameter separator, then do not set localeSpecificDecimals to true so that the default decimal separator dot (.) is used for numbers and comma is used to seperate function parameters.

- (BOOL) optimizationOn
readwritenonatomicassign

Should the parser optimize constant expressions? For example 3+1 will be optimized to 4 to benefit repeated evaluations.

- (NSDictionary*) translationStrings
readwritenonatomicassign

Returns the existing translatable strings used to report error messages.

To use this component in a localized application, set the translated versions of strings for each value that exists in the NSDictionary. By default, same NSDictionary is shared between all instances of the parser. To change translation strings, set a new NSDictionary of your own for the parser instance instead of editing the values contained in the default NSDictionary if you do not wish other parser instances not to be effected. Return value is a dictionary of key/value pairs where value is a Locale dependent, typically translated String, that may contain placeholder parameters like %

Messages may contain parameter placeholders. For example: "Variable %@ does not exist". You need to have your own messages translated accordingly.

Existing strings are:

#Strings used by the math Parser.
"Expression is empty." forKey: "ExpEmpty"

#parameter is the name of a variable:
"Variable %@ does not exist." forKey: "VarNtExst"

#parameter is the name of a variable:
"%@ is not a valid variable name." forKey: "NtVarNm"

#parameter is the math expression that failed to Parse:
"Syntax error in expression %@" forKey: "SntxErr"

#parameter is a function name:
"%@ is not a valid function name." forKey: "NtFncNm"

#parameter is a function name:
"Function %@ already exists." forKey: "FncExst"

#Parameters are function name and number of parameters:
"Function %@ must accept at least 0 parameters not %@." forKey: "WrngNPrms"

#sub expression is not valid:
"Sub expression <%@> in <%@> is not valid." forKey: "ExpNtVld"

#bracket mismatch.
"Bracket mismatch in expression <%@> at index %@." forKey: "BrcktMis"

#missing brackets.
"Missing bracket \")" in expression <%>." forKey: @"MisBrckt"

- (double) value
readnonatomicassign

Invokes evaluate method and returns the calculated value for the given expression.

Value property is a read only property which returns the result of the expression.

throws Exception if expression cannot be parsed. Return value is an IConvertible that can be converted to either Double or String using Convert class.

- (NSObject<VariableDelegate>*) variableDelegate
readwritenonatomicassign

VariableDelegate is used as a callback function that returns the values of variables when asked.

This is useful when a variable cannot be defined before the parse operation. If variableDelegate property is set, it will be used to resolve variables that were not defined at the time parse operation has started. This means that syntax errors regarding undefined variables will not be caught at parse time. This VariableDelegate (user implementation) will decide whether a variable name is valid or not. This is useful when for example the value comes from a database lookup. In some cases, the problem domain is too big to define the variables ahead of time. In such cases, it makes sense to parse with the assumption that it is a valid variable and resolve it's value when needed on demand during evaluation.


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