BoolExprParser.h

Go to the documentation of this file.
00001 /*  $Id: BoolExprParser.h,v 1.12 2005/05/09 02:43:19 sarrazip Exp $
00002     BoolExprParser.h - Boolean expression parser and syntax tree builder
00003 
00004     boolstuff - Disjunctive Normal Form boolean expression library
00005     Copyright (C) 2002-2005 Pierre Sarrazin <http://sarrazip.com/>
00006 
00007     This program is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License
00009     as published by the Free Software Foundation; either version 2
00010     of the License, or (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020     02111-1307, USA.
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     // Implementation methods:
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     // Forbidden operations:
00108     BoolExprParser(const BoolExprParser &);
00109     BoolExprParser &operator = (const BoolExprParser &);
00110 };
00111 
00112 
00113 }  // namespace boolstuff
00114 
00115 
00116 #endif  /* _H_BoolExprParser */

Generated on Thu May 10 03:56:09 2007 for BoolStuff by  doxygen 1.5.1