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