muParser: muParserTokenReader.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Examples

# muParserTokenReader.h

Go to the documentation of this file.

    00001 /*
    00002                  __________
    00003     _____   __ __\______   \_____  _______  ______  ____ _______
    00004    /     \ |  |  \|     ___/\__  \ \_  __ \/  ___/_/ __ \\_  __ \
    00005   |  Y Y  \|  |  /|    |     / __ \_|  | \/\___ \ \  ___/ |  | \/
    00006   |__|_|  /|____/ |____|    (____  /|__|  /____  > \___  >|__|
    00007         \/                       \/            \/      \/
    00008   Copyright (C) 2004-2008 Ingo Berg
    00009
    00010   Permission is hereby granted, free of charge, to any person obtaining a copy of this
    00011   software and associated documentation files (the "Software"), to deal in the Software
    00012   without restriction, including without limitation the rights to use, copy, modify,
    00013   merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
    00014   permit persons to whom the Software is furnished to do so, subject to the following conditions:
    00015
    00016   The above copyright notice and this permission notice shall be included in all copies or
    00017   substantial portions of the Software.
    00018
    00019   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
    00020   NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    00021   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00022   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00023   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    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   // Forward declaration
    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 } // namespace mu
    00152
    00153 #endif
    00154
    00155