bcParserObjC  1.1
Math Parser for Objective C, iOS and OSX
 All Classes Functions Variables Properties Pages
MathParser.h
1 //
2 // MathParser.h
3 // bcParserObjC
4 //
5 // Created by Suavi Demir on 11/9/13.
6 // Copyright (c) 2013 Suavi Demir. All rights reserved.
7 //
8 
9 #import <Foundation/Foundation.h>
10 
48 @protocol Function
49 
54 -(double)run: (NSArray *)parameters;
55 
61 @end
62 
69 @protocol Parameter
73 -(double)getValue;
74 @end
75 
84 
88 -(double) getVariableValue:(NSString *) varName;
89 @end
90 
94 @interface ParserException : NSException
95 {
96  NSString * m_InvalidPortion;
97 }
98 -(id)initWithMessage:(NSString *) message andInvalidPortion:(NSString *) invalid;
100 -(NSString *) getInvalidPortionOfExpression;
101 @end
102 
103 
110 @protocol Node<Parameter>
112 -(double) getValue;
113 
115 -(BOOL) isVariableUsed:(NSString *)name;
116 
118 -(BOOL) isFunctionUsed:(NSString *)name;
119 
122 -(void) optimize;
123 @end
124 
135 @interface MathParser : NSObject
136 {
138  NSString *m_Expression;
139 
142  BOOL m_Dirty;
143 
148 
151  NSObject<Node> *m_Node;
152 
154  NSMutableDictionary *m_Variables;
155 
157  NSMutableDictionary *m_Functions;
158 
159  // The locale to use for uppercasing and decimal points
160  NSLocale *m_Locale;
161 
162  // If true, locale specific decimal separator will be used. If false, decimal separator to use is dot(.)
163  BOOL m_LocaleSpecificDecimals;
164 
165  // An object that implements VariableDelegate protocol.
166  NSObject<VariableDelegate> *m_VariableDelegate;
167 
168  // Decimal separator related internal values.
169  char m_DecimalSeperatorChar;
170  NSString *m_DecimalSeparatorStr;
171  char m_FunctionParamSeparatorChar;
172  NSString *m_FunctionParamSeparatorStr;
173 }
174 
261 @property (nonatomic) NSString *expression;
262 
264 @property (nonatomic, readonly) double value;
265 
267 @property (nonatomic) BOOL precedingZerosAllowed;
268 
270 @property (nonatomic) NSLocale *locale;
271 
273 @property (nonatomic) BOOL localeSpecificDecimals;
274 
285 @property (nonatomic) NSObject<VariableDelegate> *variableDelegate;
286 
333 @property (nonatomic) NSDictionary * translationStrings;
334 
337 @property (nonatomic) BOOL optimizationOn;
338 
352 -(void) parse;
353 
359 -(double) evaluate;
360 
364 -(BOOL) isVariableUsed: (NSString *) varName;
365 
368 -(BOOL) isFunctionUsed: (NSString *)funcName;
369 
373 -(BOOL) isVariable:(NSString *) varName;
374 
376 -(BOOL) isConstant:(NSString *) constName;
377 
380 -(BOOL) isFunction:(NSString *) funcName;
381 
390 -(void) setVariable: (NSString *) varName withNewValue: (double) newVal maybeConstant: (bool) isConst;
391 
396 -(void) setVariable: (NSString *)varName withNewValue:(double) newVal;
397 
402 -(void) createConstant:(NSString *)varName withValue:(double)newVal;
403 
423 -(void) createFunc: (NSString *)newFuncName withImpl: (NSObject<Function> *) funcAddr;
424 
425 
495 -(void) createDefaultFuncs;
496 
504 -(void) deleteVar: (NSString *) varName;
505 
513 -(void) deleteFunc: (NSString *) funcName;
514 
515 
523 -(void) deleteAllVars;
524 
532 -(void) deleteAllFuncs;
533 
545 -(void) optimize;
546 
549 -(NSArray *) getVariables;
550 
553 -(NSArray *) getFunctions;
554 
559 -(NSArray *) getVariablesUsed;
560 
565 -(void) FreeParseTree;
566 
567 @end
void optimize()
Optimize Evaluates constant values at compile time (When Parse() is called).
Internal support protocol that represents parsed expression tree.
Definition: MathParser.h:110
int getNumberOfParameters()
Return the number of parameters that this function accepts.
MathParser class provides the capability to parse and evaluate math expressions given as strings at r...
Definition: MathParser.h:135
NSMutableDictionary * m_Functions
internal list of functions that take more than 2 parameters that are available for use in an expressi...
Definition: MathParser.h:157
double getValue()
Returns the value as NSObject which can be one of NSNumber of NSString.
BOOL m_Dirty
non-public flag that shows if parsing is needed or not.
Definition: MathParser.h:142
NSObject< Node > * m_Node
Starting node for the internal compiled representation of the expression in parsed form...
Definition: MathParser.h:151
NSString * m_Expression
protected variable that holds the expression to parse.
Definition: MathParser.h:138
Parameter protocol represents a parameter that is passed into a user defined function.
Definition: MathParser.h:69
double getValue()
Return the value for the parameter.
BOOL m_OptimizationOn
when optimization on, after the parse tree is compiled, it will be further optimized by removing sub ...
Definition: MathParser.h:147
Exception thrown by the parser when the expression has a problem.
Definition: MathParser.h:94
VariableDelegate returns the current value of a variable whose name is given.
Definition: MathParser.h:83
NSMutableDictionary * m_Variables
internal list of variables that are available for use in an expression.
Definition: MathParser.h:154
Function defines the interface that describes a function that can be used as a user defined function ...
Definition: MathParser.h:48