00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _H_BoolExprParser
00024 #define _H_BoolExprParser
00025
00026 #include <boolstuff/BoolExpr.h>
00027
00028 #include <string>
00029
00030
00031 namespace boolstuff {
00032
00033
00039 class BoolExprParser
00040 {
00041 public:
00042
00044 class Error
00045 {
00046 public:
00048 enum Code
00049 {
00053 GARBAGE_AT_END,
00054
00058 RUNAWAY_PARENTHESIS,
00059
00064 IDENTIFIER_EXPECTED,
00065
00068 STRING_EXPECTED = IDENTIFIER_EXPECTED
00069 };
00070
00072 size_t index;
00073
00075 Code code;
00076
00080 Error(size_t i, Code c) : index(i), code(c) {}
00081 };
00082
00083
00087 BoolExprParser();
00088
00092 ~BoolExprParser();
00093
00104 BoolExpr<std::string> *parse(const std::string &expr) throw(Error);
00105
00106 private:
00107
00108 std::string curInput;
00109 size_t curIndex;
00110
00111
00112 BoolExpr<std::string> *parseExpr() throw(Error);
00113 BoolExpr<std::string> *parseTerm() throw(Error);
00114 BoolExpr<std::string> *parseFactor() throw(Error);
00115 BoolExpr<std::string> *parseAtom() throw(Error);
00116 BoolExpr<std::string> *parseIdentifier() throw(Error);
00117
00118 bool atEnd();
00119 bool tokenSeen(const char *s);
00120 void skipToken(const char *s);
00121 void skipSpaces();
00122 bool isIdentifierChar(char c) const;
00123
00124
00125 BoolExprParser(const BoolExprParser &);
00126 BoolExprParser &operator = (const BoolExprParser &);
00127 };
00128
00129
00130 }
00131
00132
00133 #endif