BoolStuff 0.1

BoolExprParser.h

00001 /*  $Id: BoolExprParser.h,v 1.14 2008/10/07 02:29:03 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         {
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     // Implementation methods:
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     // Forbidden operations:
00125     BoolExprParser(const BoolExprParser &);
00126     BoolExprParser &operator = (const BoolExprParser &);
00127 };
00128 
00129 
00130 }  // namespace boolstuff
00131 
00132 
00133 #endif  /* _H_BoolExprParser */

Generated for BoolStuff by doxygen 1.7.3