00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023 #ifndef libmath_reader_h
00024 #define libmath_reader_h
00025
00026 #include <math++/error.h>
00027
00028 #include <string>
00029
00030 namespace math {
00031
00032 template<class> class TNode;
00033
00038 class EReadError : public EMath {
00039 public:
00040 EReadError(const std::string& AReason) : EMath(AReason) {}
00041 };
00042
00048 template<class T>
00049 class TReader {
00050 private:
00052 enum TToken {
00053
00054 tkInvalid, tkEnd,
00055 tkNumber = 1000, tkSymbol,
00056 tkUnEqu, tkLess, tkGreater, tkLessEqu, tkGreaterEqu,
00057 tkVeryLess, tkVeryGreat,
00058 tkEqu = '=', tkComma = ',',
00059 tkPlus = '+', tkMinus = '-', tkMul = '*', tkDiv = '/', tkPow = '^',
00060 tkRndOpen = '(', tkRndClose = ')', tkBrOpen = '[', tkBrClose = ']',
00061 tkAngOpen = '<', tkAngClose = '>', tkSetOpen = '{', tkSetClose = '}'
00062 };
00063
00064 std::string FExprStr;
00065 std::string::size_type FPos;
00066
00067 TToken FToken;
00068 T FNumber;
00069 std::string FSymbol;
00070
00071 private:
00072 TReader(const std::string& AInput);
00073
00075 TNode<T> *equation(bool get);
00076
00077 TNode<T> *expr(bool get);
00079 TNode<T> *simpleExpr(bool get);
00081 TNode<T> *term(bool get);
00083 TNode<T> *factor(bool get);
00085 TNode<T> *prim(bool get);
00086
00088 TNode<T> *createSymbol();
00090 TNode<T> *param();
00091
00093 bool eof() const;
00094
00096 TToken nextToken();
00098 bool readOperator();
00100 bool readNumber();
00102 bool readSymbol();
00103
00105 static std::string tok2str(TToken AToken);
00107 void consume(TToken AToken);
00108
00109 public:
00114 static TNode<T> *parse(const std::string& AInput, bool AEquation = false);
00115 };
00116
00117 }
00118
00119 #include <math++/reader.tcc>
00120
00121 #endif