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 {
00050 GARBAGE_AT_END,
00051 RUNAWAY_PARENTHESIS,
00052 STRING_EXPECTED
00053 };
00054
00056 size_t index;
00058 Code code;
00059
00063 Error(size_t i, Code c) : index(i), code(c) {}
00064 };
00065
00066
00070 BoolExprParser();
00071
00075 ~BoolExprParser();
00076
00087 BoolExpr<std::string> *parse(const std::string &expr) throw(Error);
00088
00089 private:
00090
00091 std::string curInput;
00092 size_t curIndex;
00093
00094
00095 BoolExpr<std::string> *parseExpr() throw(Error);
00096 BoolExpr<std::string> *parseTerm() throw(Error);
00097 BoolExpr<std::string> *parseFactor() throw(Error);
00098 BoolExpr<std::string> *parseAtom() throw(Error);
00099 BoolExpr<std::string> *parseString() throw(Error);
00100
00101 bool atEnd();
00102 bool tokenSeen(const char *s);
00103 void skipToken(const char *s);
00104 void skipSpaces();
00105 bool isStringChar(char c) const;
00106
00107
00108 BoolExprParser(const BoolExprParser &);
00109 BoolExprParser &operator = (const BoolExprParser &);
00110 };
00111
00112
00113 }
00114
00115
00116 #endif