00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MU_PARSER_TOKEN_READER_H
00027 #define MU_PARSER_TOKEN_READER_H
00028
00029 #include <cassert>
00030 #include <cstdio>
00031 #include <cstring>
00032 #include <map>
00033 #include <memory>
00034 #include <stack>
00035 #include <string>
00036
00037 #include "muParserDef.h"
00038 #include "muParserToken.h"
00039
00045 namespace mu
00046 {
00047
00048 class ParserBase;
00049
00053 class ParserTokenReader
00054 {
00055 private:
00056
00057 typedef ParserToken<value_type, string_type> token_type;
00058
00059 public:
00060
00061 ParserTokenReader(ParserBase *a_pParent);
00062 ParserTokenReader* Clone(ParserBase *a_pParent) const;
00063
00064 void AddValIdent(identfun_type a_pCallback);
00065 void SetVarCreator(facfun_type a_pFactory, void *pUserData);
00066 void SetFormula(const string_type &a_strFormula);
00067 void SetArgSep(char_type cArgSep);
00068
00069 int GetPos() const;
00070 const string_type& GetFormula() const;
00071 const varmap_type& GetUsedVar() const;
00072 char_type GetArgSep() const;
00073
00074 void IgnoreUndefVar(bool bIgnore);
00075 void ReInit();
00076 token_type ReadNextToken();
00077
00078 private:
00079
00086 enum ESynCodes
00087 {
00088 noBO = 1 << 0,
00089 noBC = 1 << 1,
00090 noVAL = 1 << 2,
00091 noVAR = 1 << 3,
00092 noARG_SEP = 1 << 4,
00093 noFUN = 1 << 5,
00094 noOPT = 1 << 6,
00095 noPOSTOP = 1 << 7,
00096 noINFIXOP = 1 << 8,
00097 noEND = 1 << 9,
00098 noSTR = 1 << 10,
00099 noASSIGN = 1 << 11,
00100 noANY = ~0
00101 };
00102
00103 ParserTokenReader(const ParserTokenReader &a_Reader);
00104 ParserTokenReader& operator=(const ParserTokenReader &a_Reader);
00105 void Assign(const ParserTokenReader &a_Reader);
00106
00107 void SetParent(ParserBase *a_pParent);
00108 int ExtractToken(const char_type *a_szCharSet,
00109 string_type &a_strTok,
00110 int a_iPos) const;
00111 bool IsBuiltIn(token_type &a_Tok);
00112 bool IsArgSep(token_type &a_Tok);
00113 bool IsEOF(token_type &a_Tok);
00114 bool IsInfixOpTok(token_type &a_Tok);
00115 bool IsFunTok(token_type &a_Tok);
00116 bool IsPostOpTok(token_type &a_Tok);
00117 bool IsOprt(token_type &a_Tok);
00118 bool IsValTok(token_type &a_Tok);
00119 bool IsVarTok(token_type &a_Tok);
00120 bool IsStrVarTok(token_type &a_Tok);
00121 bool IsUndefVarTok(token_type &a_Tok);
00122 bool IsString(token_type &a_Tok);
00123 void Error(EErrorCodes a_iErrc,
00124 int a_iPos = -1,
00125 const string_type &a_sTok = string_type() ) const;
00126
00127 token_type& SaveBeforeReturn(const token_type &tok);
00128
00129 ParserBase *m_pParser;
00130 string_type m_strFormula;
00131 int m_iPos;
00132 int m_iSynFlags;
00133 bool m_bIgnoreUndefVar;
00134
00135 const funmap_type *m_pFunDef;
00136 const funmap_type *m_pPostOprtDef;
00137 const funmap_type *m_pInfixOprtDef;
00138 const funmap_type *m_pOprtDef;
00139 const valmap_type *m_pConstDef;
00140 const strmap_type *m_pStrVarDef;
00141 varmap_type *m_pVarDef;
00142 facfun_type m_pFactory;
00143 void *m_pFactoryData;
00144 std::vector<identfun_type> m_vIdentFun;
00145 varmap_type m_UsedVar;
00146 value_type m_fZero;
00147 int m_iBrackets;
00148 token_type m_lastTok;
00149 char_type m_cArgSep;
00150 };
00151 }
00152
00153 #endif
00154
00155