00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00019 #ifndef _MATHPARSER_H_
00020 #define _MATHPARSER_H_
00021
00022 #include "MathParserDll.h"
00023 #include "GenApi/Types.h"
00024 #include "GenApi/GenApiDll.h"
00025 #include "StrMap.h"
00026 #include "Lexer.h"
00027
00028 #include <vector>
00029
00030 #ifdef _MSC_VER // *JS*
00031 # pragma warning(push)
00032 # pragma warning(disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of class 'yyy'
00033 #endif
00034
00035 #define ORIGINAL_STACK_SIZE 64
00036
00037 extern const double DblErR;
00038 extern const double DblNiN;
00039
00040
00041 typedef double ( *OneArgFunc ) ( double arg );
00042 typedef char* ( *MultiArgFunc ) ( int paramcnt, double* args,
00043 CStrMap* strparams, double* result );
00044 typedef int ( *PrmSrchFunc ) ( const char* str, size_t len, double* value,
00045 void* param );
00051 class MATHPARSERDLL_API CMathParser
00052 {
00053 typedef enum
00054 {
00055
00056 OP_SHL, OP_SHR, OP_POW,
00057 OP_LOGIC_NEQ, OP_LOGIC_GEQ, OP_LOGIC_LEQ,
00058 OP_LOGIC_AND, OP_LOGIC_OR,
00059 OP_COMSTART, OP_ASSIGN,
00060 OP_OBR,
00061 OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_UNK,
00062 OP_XOR, OP_NOT, OP_AND, OP_OR,
00063 OP_EQU, OP_GREATER, OP_LESS,
00064 OP_LOGIC, OP_LOGIC_SEP, OP_CBR, OP_COMMA,
00065 OP_FORMULAEND,
00066 OP_INDEX_TO_VAR, OP_FUNC_ONEARG, OP_FUNC_MULTIARG
00067 } OperType_t;
00068 static const signed char OpPriorities[OP_FUNC_MULTIARG + 1];
00069 typedef struct Operation
00070 {
00071 OperType_t OperType;
00072 const void* Func;
00073 signed char PrevValTop;
00074 CStrMap* StrParams;
00075 explicit Operation() : Func( 0 ), PrevValTop( 0 ), StrParams( 0 ) {}
00076 explicit Operation( OperType_t op ) : OperType( op ), Func( 0 ), PrevValTop( 0 ), StrParams( 0 ) {}
00077 explicit Operation( OperType_t op, const void* p, signed char a, CStrMap* pM ) : OperType( op ), Func( p ), PrevValTop( a ), StrParams( pM ) {}
00078 } Operation;
00079 static const Operation BrOp;
00080 static const Operation CbrOp;
00081 static const Operation NegOp;
00082 static const Operation ItvOp;
00083 static const Operation CommaOp;
00084 std::vector<Operation> OpStack;
00085 std::vector<Operation> OpStackEval;
00086 std::vector<double> ValStack;
00087 std::vector<double> ValStackEval;
00088 int OpTop, ValTop;
00089 int ObrDist;
00090 CLexer Lexer;
00091 CStrMap* VarParams;
00092 std::vector<char> errbuf;
00093 static CStaticFuncMapDouble DoubleFunctions;
00094 static CSymTable MathSymTable;
00095 const char* ParseFormula( bool ConvertUpperCase );
00096 const char* PrepareFormula();
00097 const char* Calc();
00098 const char* CalcToObr();
00099 public:
00100 CStrMap* Parameters;
00101 CStrMap* ExtFunctions;
00102 PrmSrchFunc MoreParams;
00103 void* ParamFuncParam;
00104 CMathParser( void );
00105 const char* Parse( const char* Formula, bool ConvertUpperCase );
00106 const char* Eval( double* result );
00107 ~CMathParser();
00108 };
00109
00110 #ifdef _MSC_VER // *JS*
00111 # pragma warning(pop)
00112 #endif
00113
00114 #endif //_MATHPARSER_H_