Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

reader.h

00001 00002 // Math Type Library 00003 // $Id: reader.h,v 1.6 2002/04/20 06:35:05 cparpart Exp $ 00004 // (This file contains the reader (parser) specific interface) 00005 // 00006 // Copyright (c) 2002 by Christian Parpart <cparpart@surakware.net> 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public License 00019 // along with this library; see the file COPYING.LIB. If not, write to 00020 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 // Boston, MA 02111-1307, USA. 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 /* TAKE CARE : THE VALUES ARE HARD CODED */ 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; // holds the current parsed expression 00065 std::string::size_type FPos;// holds the current read index 00066 00067 TToken FToken; // holds current parsed token id 00068 T FNumber; // holds last read number 00069 std::string FSymbol; // holds last read symbol 00070 00071 private: 00072 TReader(const std::string& AInput); 00073 00075 TNode<T> *equation(bool get); 00076 // parses an expression (really any expression, even sub equations) 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 } // namespace math 00118 00119 #include <math++/reader.tcc> 00120 00121 #endif

Generated on Sun Aug 22 06:47:45 2004 for MathTypeLibrary(libmath++) by doxygen 1.3.7