parser.h
Go to the documentation of this file.
/********************* */
#include "cvc4parser_public.h"
#ifndef __CVC4__PARSER__PARSER_STATE_H
#define __CVC4__PARSER__PARSER_STATE_H
#include <string>
#include <set>
#include <list>
#include <cassert>
#include "parser/input.h"
#include "parser/parser_exception.h"
#include "expr/expr.h"
#include "expr/symbol_table.h"
#include "expr/kind.h"
#include "expr/expr_stream.h"
namespace CVC4 {
// Forward declarations
class BooleanType;
class ExprManager;
class Command;
class FunctionType;
class Type;
namespace parser {
class Input;
enum DeclarationCheck {
CHECK_DECLARED,
CHECK_UNDECLARED,
CHECK_NONE
};/* enum DeclarationCheck */
inline std::ostream& operator<<(std::ostream& out, DeclarationCheck check) CVC4_PUBLIC;
inline std::ostream& operator<<(std::ostream& out, DeclarationCheck check) {
switch(check) {
case CHECK_NONE:
return out << "CHECK_NONE";
case CHECK_DECLARED:
return out << "CHECK_DECLARED";
case CHECK_UNDECLARED:
return out << "CHECK_UNDECLARED";
default:
return out << "DeclarationCheck!UNKNOWN";
}
}
enum SymbolType {
SYM_VARIABLE,
SYM_SORT
};/* enum SymbolType */
inline std::ostream& operator<<(std::ostream& out, SymbolType type) CVC4_PUBLIC;
inline std::ostream& operator<<(std::ostream& out, SymbolType type) {
switch(type) {
case SYM_VARIABLE:
return out << "SYM_VARIABLE";
case SYM_SORT:
return out << "SYM_SORT";
default:
return out << "SymbolType!UNKNOWN";
}
}
class CVC4_PUBLIC Parser {
friend class ParserBuilder;
ExprManager *d_exprManager;
Input *d_input;
SymbolTable d_symtabAllocated;
SymbolTable* d_symtab;
size_t d_assertionLevel;
std::set<std::string> d_reservedSymbols;
size_t d_anonymousFunctionCount;
bool d_done;
bool d_checksEnabled;
bool d_strictMode;
bool d_parseOnly;
bool d_canIncludeFile;
bool d_logicIsForced;
std::string d_forcedLogic;
std::set<Kind> d_logicOperators;
std::set<std::string> d_attributesWarnedAbout;
std::set<Type> d_unresolved;
std::list<Command*> d_commandQueue;
Expr getSymbol(const std::string& var_name, SymbolType type);
protected:
Parser(ExprManager* exprManager, Input* input, bool strictMode = false, bool parseOnly = false);
public:
virtual ~Parser() {
delete d_input;
}
inline ExprManager* getExprManager() const {
return d_exprManager;
}
inline Input* getInput() const {
return d_input;
}
void setInput(Input* input) {
delete d_input;
d_input = input;
d_input->setParser(*this);
d_done = false;
}
inline bool done() const {
return d_done;
}
inline void setDone(bool done = true) {
d_done = done;
}
void enableChecks() { d_checksEnabled = true; }
void disableChecks() { d_checksEnabled = false; }
void enableStrictMode() { d_strictMode = true; }
void disableStrictMode() { d_strictMode = false; }
bool strictModeEnabled() { return d_strictMode; }
void allowIncludeFile() { d_canIncludeFile = true; }
void disallowIncludeFile() { d_canIncludeFile = false; }
bool canIncludeFile() const { return d_canIncludeFile; }
virtual bool logicIsSet() { return false; }
void forceLogic(const std::string& logic) { assert(!d_logicIsForced); d_logicIsForced = true; d_forcedLogic = logic; }
const std::string& getForcedLogic() const { return d_forcedLogic; }
bool logicIsForced() const { return d_logicIsForced; }
Expr getVariable(const std::string& name);
Expr getFunction(const std::string& name);
Type getSort(const std::string& sort_name);
Type getSort(const std::string& sort_name,
const std::vector<Type>& params);
size_t getArity(const std::string& sort_name);
bool isDeclared(const std::string& name, SymbolType type = SYM_VARIABLE);
void checkDeclaration(const std::string& name, DeclarationCheck check,
SymbolType type = SYM_VARIABLE,
std::string notes = "") throw(ParserException);
void reserveSymbolAtAssertionLevel(const std::string& name);
void checkFunctionLike(const std::string& name) throw(ParserException);
void checkArity(Kind kind, unsigned numArgs) throw(ParserException);
void checkOperator(Kind kind, unsigned numArgs) throw(ParserException);
Type getType(const std::string& var_name, SymbolType type = SYM_VARIABLE);
Expr mkVar(const std::string& name, const Type& type,
uint32_t flags = ExprManager::VAR_FLAG_NONE);
std::vector<Expr>
mkVars(const std::vector<std::string> names, const Type& type,
uint32_t flags = ExprManager::VAR_FLAG_NONE);
Expr mkBoundVar(const std::string& name, const Type& type);
std::vector<Expr> mkBoundVars(const std::vector<std::string> names, const Type& type);
Expr mkFunction(const std::string& name, const Type& type,
uint32_t flags = ExprManager::VAR_FLAG_NONE);
Expr mkAnonymousFunction(const std::string& prefix, const Type& type,
uint32_t flags = ExprManager::VAR_FLAG_NONE);
void defineVar(const std::string& name, const Expr& val,
bool levelZero = false);
void defineFunction(const std::string& name, const Expr& val,
bool levelZero = false);
void defineType(const std::string& name, const Type& type);
void defineType(const std::string& name,
const std::vector<Type>& params, const Type& type);
void defineParameterizedType(const std::string& name,
const std::vector<Type>& params,
const Type& type);
SortType mkSort(const std::string& name,
uint32_t flags = ExprManager::SORT_FLAG_NONE);
SortConstructorType mkSortConstructor(const std::string& name, size_t arity);
SortType mkUnresolvedType(const std::string& name);
SortConstructorType mkUnresolvedTypeConstructor(const std::string& name,
size_t arity);
SortConstructorType mkUnresolvedTypeConstructor(const std::string& name,
const std::vector<Type>& params);
bool isUnresolvedType(const std::string& name);
std::vector<DatatypeType>
mkMutualDatatypeTypes(const std::vector<Datatype>& datatypes);
void addOperator(Kind kind);
void preemptCommand(Command* cmd);
bool isBoolean(const std::string& name);
bool isFunctionLike(const std::string& name);
bool isDefinedFunction(const std::string& name);
bool isDefinedFunction(Expr func);
bool isPredicate(const std::string& name);
Command* nextCommand() throw(ParserException);
Expr nextExpression() throw(ParserException);
inline void warning(const std::string& msg) {
d_input->warning(msg);
}
void attributeNotSupported(const std::string& attr);
inline void parseError(const std::string& msg) throw(ParserException) {
d_input->parseError(msg);
}
inline void unexpectedEOF(const std::string& msg) throw(ParserException) {
d_input->parseError(msg, true);
}
inline void unimplementedFeature(const std::string& msg) throw(ParserException) {
if(!d_parseOnly) {
parseError("Unimplemented feature: " + msg);
}
}
inline size_t scopeLevel() const { return d_symtab->getLevel(); }
inline void pushScope(bool bindingLevel = false) {
d_symtab->pushScope();
if(!bindingLevel) {
d_assertionLevel = scopeLevel();
}
}
inline void popScope() {
d_symtab->popScope();
if(scopeLevel() < d_assertionLevel) {
d_assertionLevel = scopeLevel();
d_reservedSymbols.clear();
}
}
inline void useDeclarationsFrom(Parser* parser) {
if(parser == NULL) {
d_symtab = &d_symtabAllocated;
} else {
d_symtab = parser->d_symtab;
}
}
inline void useDeclarationsFrom(SymbolTable* symtab) {
d_symtab = symtab;
}
inline SymbolTable* getSymbolTable() const {
return d_symtab;
}
class ExprStream : public CVC4::ExprStream {
Parser* d_parser;
public:
ExprStream(Parser* parser) : d_parser(parser) {}
~ExprStream() { delete d_parser; }
Expr nextExpr() { return d_parser->nextExpression(); }
};/* class Parser::ExprStream */
};/* class Parser */
}/* CVC4::parser namespace */
}/* CVC4 namespace */
#endif /* __CVC4__PARSER__PARSER_STATE_H */
Type
void * Type
Definition c_interface_defs.h:48
ExprManager
void * ExprManager
Definition c_interface_defs.h:43
CVC4::Command
Definition command.h:184
CVC4::DatatypeType
Class encapsulating the datatype type.
Definition type.h:615
CVC4::Datatype
The representation of an inductive datatype.
Definition datatype.h:423
CVC4::ExprManager
Definition expr_manager.h:124
CVC4::ExprStream
A pure-virtual stream interface for expressions.
Definition expr_stream.h:30
CVC4::Expr
Class encapsulating CVC4 expressions and methods for constructing new expressions.
Definition expr.h:227
CVC4::SortConstructorType
Class encapsulating a user-defined sort constructor.
Definition type.h:536
CVC4::SortType
Class encapsulating a user-defined sort.
Definition type.h:515
CVC4::SymbolTable
A convenience class for handling scoped declarations.
Definition symbol_table.h:48
CVC4::SymbolTable::pushScope
void pushScope()
Push a scope level.
CVC4::SymbolTable::getLevel
size_t getLevel() const
Get the current level of this symbol table.
CVC4::SymbolTable::popScope
void popScope()
Pop a scope level.
CVC4::Type
Class encapsulating CVC4 expression types.
Definition type.h:89
CVC4::parser::Input
An input to be parsed.
Definition input.h:86
CVC4::parser::Input::setParser
virtual void setParser(Parser &parser)=0
Set the Parser object for this input.
CVC4::parser::Input::warning
virtual void warning(const std::string &msg)=0
Issue a warning to the user, with source file, line, and column info.
CVC4::parser::Input::parseError
virtual void parseError(const std::string &msg, bool eofException=false)=0
Throws a ParserException with the given message.
CVC4::parser::ParserBuilder
A builder for input language parsers.
Definition parser_builder.h:42
CVC4::parser::ParserException
Definition parser_exception.h:31
CVC4::parser::Parser::ExprStream
An expression stream interface for a parser.
Definition parser.h:614
CVC4::parser::Parser::ExprStream::ExprStream
ExprStream(Parser *parser)
Definition parser.h:617
CVC4::parser::Parser::ExprStream::~ExprStream
~ExprStream()
Virtual destructor; this implementation does nothing.
Definition parser.h:618
CVC4::parser::Parser::ExprStream::nextExpr
Expr nextExpr()
Get the next expression in the stream (advancing the stream pointer as a side effect....
Definition parser.h:619
CVC4::parser::Parser
This class encapsulates all of the state of a parser, including the name of the file,...
Definition parser.h:106
CVC4::parser::Parser::isDeclared
bool isDeclared(const std::string &name, SymbolType type=SYM_VARIABLE)
Checks if a symbol has been declared.
CVC4::parser::Parser::canIncludeFile
bool canIncludeFile() const
Definition parser.h:273
CVC4::parser::Parser::checkDeclaration
void checkDeclaration(const std::string &name, DeclarationCheck check, SymbolType type=SYM_VARIABLE, std::string notes="")
Checks if the declaration policy we want to enforce holds for the given symbol.
CVC4::parser::Parser::parseError
void parseError(const std::string &msg)
Raise a parse error with the given message.
Definition parser.h:515
CVC4::parser::Parser::getExprManager
ExprManager * getExprManager() const
Get the associated ExprManager.
Definition parser.h:225
CVC4::parser::Parser::~Parser
virtual ~Parser()
Definition parser.h:220
CVC4::parser::Parser::disableStrictMode
void disableStrictMode()
Disable strict parsing.
Definition parser.h:267
CVC4::parser::Parser::useDeclarationsFrom
void useDeclarationsFrom(Parser *parser)
Set the current symbol table used by this parser.
Definition parser.h:589
CVC4::parser::Parser::scopeLevel
size_t scopeLevel() const
Gets the current declaration level.
Definition parser.h:547
CVC4::parser::Parser::enableChecks
void enableChecks()
Enable semantic checks during parsing.
Definition parser.h:257
CVC4::parser::Parser::getInput
Input * getInput() const
Get the associated input.
Definition parser.h:230
CVC4::parser::Parser::getVariable
Expr getVariable(const std::string &name)
Returns a variable, given a name.
CVC4::parser::Parser::attributeNotSupported
void attributeNotSupported(const std::string &attr)
Issue a warning to the user, but only once per attribute.
CVC4::parser::Parser::forceLogic
void forceLogic(const std::string &logic)
Definition parser.h:279
CVC4::parser::Parser::done
bool done() const
Check if we are done – either the end of input has been reached, or some error has been encountered.
Definition parser.h:247
CVC4::parser::Parser::enableStrictMode
void enableStrictMode()
Enable strict parsing, according to the language standards.
Definition parser.h:263
CVC4::parser::Parser::useDeclarationsFrom
void useDeclarationsFrom(SymbolTable *symtab)
Definition parser.h:597
CVC4::parser::Parser::getForcedLogic
const std::string & getForcedLogic() const
Definition parser.h:280
CVC4::parser::Parser::unexpectedEOF
void unexpectedEOF(const std::string &msg)
Unexpectedly encountered an EOF.
Definition parser.h:520
CVC4::parser::Parser::getSort
Type getSort(const std::string &sort_name)
Returns a sort, given a name.
CVC4::parser::Parser::popScope
void popScope()
Definition parser.h:556
CVC4::parser::Parser::getArity
size_t getArity(const std::string &sort_name)
Returns arity of a (parameterized) sort, given a name and args.
CVC4::parser::Parser::Parser
Parser(ExprManager *exprManager, Input *input, bool strictMode=false, bool parseOnly=false)
Create a parser state.
CVC4::parser::Parser::pushScope
void pushScope(bool bindingLevel=false)
Definition parser.h:549
CVC4::parser::Parser::disableChecks
void disableChecks()
Disable semantic checks during parsing.
Definition parser.h:260
CVC4::parser::Parser::getSort
Type getSort(const std::string &sort_name, const std::vector< Type > &params)
Returns a (parameterized) sort, given a name and args.
CVC4::parser::Parser::disallowIncludeFile
void disallowIncludeFile()
Definition parser.h:272
CVC4::parser::Parser::getFunction
Expr getFunction(const std::string &name)
Returns a function, given a name.
CVC4::parser::Parser::nextExpression
Expr nextExpression()
Parse and return the next expression.
CVC4::parser::Parser::getSymbolTable
SymbolTable * getSymbolTable() const
Definition parser.h:601
CVC4::parser::Parser::setInput
void setInput(Input *input)
Deletes and replaces the current parser input.
Definition parser.h:235
CVC4::parser::Parser::strictModeEnabled
bool strictModeEnabled()
Definition parser.h:269
CVC4::parser::Parser::allowIncludeFile
void allowIncludeFile()
Definition parser.h:271
CVC4::parser::Parser::logicIsForced
bool logicIsForced() const
Definition parser.h:281
CVC4::parser::Parser::unimplementedFeature
void unimplementedFeature(const std::string &msg)
If we are parsing only, don't raise an exception; if we are not, raise a parse error with the given m...
Definition parser.h:538
CVC4::parser::Parser::setDone
void setDone(bool done=true)
Sets the done flag.
Definition parser.h:252
CVC4::parser::Parser::logicIsSet
virtual bool logicIsSet()
Expose the functionality from SMT/SMT2 parsers, while making implementation optional by returning fal...
Definition parser.h:277
CVC4_PUBLIC
#define CVC4_PUBLIC
Definition cvc4_public.h:30
cvc4parser_public.h
Macros that should be defined everywhere during the building of the libraries and driver binary,...
expr.h
expr_stream.h
A stream interface for expressions.
input.h
Base for parser inputs.
kind.h
CVC4::kind::Kind_t
Kind_t
Definition kind.h:60
CVC4::parser::DeclarationCheck
DeclarationCheck
Types of check for the symols.
Definition parser.h:48
CVC4::parser::CHECK_NONE
@ CHECK_NONE
Don't check anything.
Definition parser.h:54
CVC4::parser::CHECK_UNDECLARED
@ CHECK_UNDECLARED
Enforce that the symbol has not been declared.
Definition parser.h:52
CVC4::parser::CHECK_DECLARED
@ CHECK_DECLARED
Enforce that the symbol has been declared.
Definition parser.h:50
CVC4::parser::operator<<
std::ostream & operator<<(std::ostream &out, DeclarationCheck check)
Returns a string representation of the given object (for debugging).
Definition parser.h:62
CVC4::parser::SymbolType
SymbolType
Types of symbols.
Definition parser.h:78
CVC4::parser::SYM_SORT
@ SYM_SORT
Sorts.
Definition parser.h:82
CVC4::parser::SYM_VARIABLE
@ SYM_VARIABLE
Variables.
Definition parser.h:80
CVC4
Definition expr.h:106
std
STL namespace.
parser_exception.h
Exception class for parse errors.
symbol_table.h
Convenience class for scoping variable and type declarations.