00001
00006 #ifndef _Tokenizer_h
00007 #define _Tokenizer_h
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "FunctionTree.h"
00018 #include "ParseError.h"
00019
00020
00021
00022
00023
00024 class Tokenizer
00025 {
00026 public:
00027
00028 enum TokenType
00029 {
00030 NONE,
00031 NUMBER,
00032 VARIABLE,
00033 PLUS,
00034 MINUS,
00035 MULTIPLY,
00036 DIVIDE,
00037 POWER,
00038 FUNCTION,
00039 OPEN_PAREN,
00040 CLOSE_PAREN,
00041 END
00042 };
00043
00045 struct FunctionInfo {
00046 FunctionTree::UnaryOperator function;
00047 bool differentiable;
00048 };
00049
00051 typedef std::map<wxString, FunctionInfo> FunctionMap;
00052
00053
00054
00061 Tokenizer(const wxString& input,
00062 VariableNames& rVariables,
00063 bool addVariables,
00064 FunctionMap functions = FunctionMap());
00065
00068 ~Tokenizer(void);
00069
00070
00071
00072
00073
00074
00082 TokenType Peek() throw(ParseError);
00083
00095 auto_ptr<FunctionTree> Consume();
00096
00102 void Expect(TokenType expectedToken) throw(ParseError);
00103
00104
00105
00108 const wxString& Input() const;
00109
00114 unsigned Position() const;
00115
00116
00117
00120 bool AllDifferentiable() const;
00121
00122 protected:
00123 private:
00124
00127 void TrimInput();
00128
00132 static bool IsDoubleChar(wxChar c);
00133
00137 static bool IsIdentifierChar(wxChar c);
00138
00140 const wxString mInput;
00141 wxString mWorkingInput;
00142 unsigned mPosition;
00143 int mTokenLength;
00144 TokenType mTokenType;
00145 auto_ptr<FunctionTree> mapTokenNode;
00147 bool mDifferentiable;
00148
00149 VariableNames& mrVariables;
00150 bool mAddVariables;
00151 FunctionMap mFunctionMap;
00152
00153 static wxChar mDecimalSeparator;
00154 };
00155
00156
00157
00158
00159
00160
00161
00162 #endif // _Tokenizer_h