/usr/include/boolstuff-0.1/boolstuff/BoolExprParser.h is in boolstuff-dev 0.1.15-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | /* $Id: BoolExprParser.h,v 1.15 2013/03/03 06:48:45 sarrazip Exp $
BoolExprParser.h - Boolean expression parser and syntax tree builder
boolstuff - Disjunctive Normal Form boolean expression library
Copyright (C) 2002-2005 Pierre Sarrazin <http://sarrazip.com/>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef _H_BoolExprParser
#define _H_BoolExprParser
#include <boolstuff/BoolExpr.h>
#include <string>
namespace boolstuff {
/**
Parser for a language of boolean expressions.
The parse() method dynamically allocates a binary tree of nodes that
represents the syntactic structure of a textual boolean expression.
*/
class BoolExprParser
{
public:
/** Error descriptor. */
class Error
{
public:
/** Possible error codes returned by the parser. */
enum Code
{
/** Unexpected characters follow the position that the parser
views as the end of the expression.
*/
GARBAGE_AT_END,
/** An opening parenthesis has no corresponding closing
parenthesis.
*/
RUNAWAY_PARENTHESIS,
/** A variable identifier was expected.
Until version 0.1.11 of this library, this enumerated name
was STRING_EXPECTED, but the term "string" was too general.
*/
IDENTIFIER_EXPECTED,
/** Deprecated older enumerated name for IDENTIFIER_EXPECTED.
*/
STRING_EXPECTED = IDENTIFIER_EXPECTED
};
/** Index (>=0) in the input string where the error was detected. */
size_t index;
/** Code that gives the type of the error */
Code code;
/**
Initializes an error object with the given index and error.
*/
Error(size_t i, Code c) : index(i), code(c) {}
};
/**
Initializes the parser.
*/
BoolExprParser();
/**
Destroys the parser and frees the associated resources.
*/
~BoolExprParser();
/**
Parses a textual boolean expression and creates a binary syntax tree.
Dynamically allocates a tree of nodes that represents the
syntactic structure of 'expr'.
The returned tree must eventually be destroyed with operator delete.
@param expr text of the boolean expression to parse
@returns the root of the created tree
@throws Error describes a parsing error
*/
BoolExpr<std::string> *parse(const std::string &expr) throw(Error);
private:
std::string curInput;
size_t curIndex;
// Implementation methods:
BoolExpr<std::string> *parseExpr() throw(Error);
BoolExpr<std::string> *parseTerm() throw(Error);
BoolExpr<std::string> *parseFactor() throw(Error);
BoolExpr<std::string> *parseAtom() throw(Error);
BoolExpr<std::string> *parseIdentifier() throw(Error);
bool atEnd();
bool tokenSeen(const char *s);
void skipToken(const char *s);
void skipSpaces();
bool isIdentifierChar(char c) const;
// Forbidden operations:
BoolExprParser(const BoolExprParser &);
BoolExprParser &operator = (const BoolExprParser &);
};
} // namespace boolstuff
#endif /* _H_BoolExprParser */
|