cvc4-1.4
|
This class encapsulates all of the state of a parser, including the name of the file, line number and column information, and in-scope declarations. More...
#include <parser.h>
Data Structures | |
class | ExprStream |
An expression stream interface for a parser. More... | |
Public Member Functions | |
virtual | ~Parser () |
ExprManager * | getExprManager () const |
Get the associated ExprManager . | |
Input * | getInput () const |
Get the associated input. | |
void | setInput (Input *input) |
Deletes and replaces the current parser input. | |
bool | done () const |
Check if we are done – either the end of input has been reached, or some error has been encountered. | |
void | setDone (bool done=true) |
Sets the done flag. | |
void | enableChecks () |
Enable semantic checks during parsing. | |
void | disableChecks () |
Disable semantic checks during parsing. | |
void | enableStrictMode () |
Enable strict parsing, according to the language standards. | |
void | disableStrictMode () |
Disable strict parsing. | |
bool | strictModeEnabled () |
void | allowIncludeFile () |
void | disallowIncludeFile () |
bool | canIncludeFile () const |
virtual bool | logicIsSet () |
Expose the functionality from SMT/SMT2 parsers, while making implementation optional by returning false by default. | |
void | forceLogic (const std::string &logic) |
const std::string & | getForcedLogic () const |
bool | logicIsForced () const |
Expr | getVariable (const std::string &name) |
Returns a variable, given a name. | |
Expr | getFunction (const std::string &name) |
Returns a function, given a name. | |
Type | getSort (const std::string &sort_name) |
Returns a sort, given a name. | |
Type | getSort (const std::string &sort_name, const std::vector< Type > ¶ms) |
Returns a (parameterized) sort, given a name and args. | |
size_t | getArity (const std::string &sort_name) |
Returns arity of a (parameterized) sort, given a name and args. | |
bool | isDeclared (const std::string &name, SymbolType type=SYM_VARIABLE) |
Checks if a symbol has been declared. | |
void | checkDeclaration (const std::string &name, DeclarationCheck check, SymbolType type=SYM_VARIABLE, std::string notes="") throw (ParserException) |
Checks if the declaration policy we want to enforce holds for the given symbol. | |
void | reserveSymbolAtAssertionLevel (const std::string &name) |
Reserve a symbol at the assertion level. | |
void | checkFunctionLike (const std::string &name) throw (ParserException) |
Checks whether the given name is bound to a function. | |
void | checkArity (Kind kind, unsigned numArgs) throw (ParserException) |
Check that kind can accept numArgs arguments. | |
void | checkOperator (Kind kind, unsigned numArgs) throw (ParserException) |
Check that kind is a legal operator in the current logic and that it can accept numArgs arguments. | |
Type | getType (const std::string &var_name, SymbolType type=SYM_VARIABLE) |
Returns the type for the variable with the given name. | |
Expr | mkVar (const std::string &name, const Type &type, uint32_t flags=ExprManager::VAR_FLAG_NONE) |
Create a new CVC4 variable expression of the given type. | |
std::vector< Expr > | mkVars (const std::vector< std::string > names, const Type &type, uint32_t flags=ExprManager::VAR_FLAG_NONE) |
Create a set of new CVC4 variable expressions of the given type. | |
Expr | mkBoundVar (const std::string &name, const Type &type) |
Create a new CVC4 bound variable expression of the given type. | |
std::vector< Expr > | mkBoundVars (const std::vector< std::string > names, const Type &type) |
Create a set of new CVC4 bound variable expressions of the given type. | |
Expr | mkFunction (const std::string &name, const Type &type, uint32_t flags=ExprManager::VAR_FLAG_NONE) |
Create a new CVC4 function expression of the given type. | |
Expr | mkAnonymousFunction (const std::string &prefix, const Type &type, uint32_t flags=ExprManager::VAR_FLAG_NONE) |
Create a new CVC4 function expression of the given type, appending a unique index to its name. | |
void | defineVar (const std::string &name, const Expr &val, bool levelZero=false) |
Create a new variable definition (e.g., from a let binding). | |
void | defineFunction (const std::string &name, const Expr &val, bool levelZero=false) |
Create a new function definition (e.g., from a define-fun). | |
void | defineType (const std::string &name, const Type &type) |
Create a new type definition. | |
void | defineType (const std::string &name, const std::vector< Type > ¶ms, const Type &type) |
Create a new (parameterized) type definition. | |
void | defineParameterizedType (const std::string &name, const std::vector< Type > ¶ms, const Type &type) |
Create a new type definition (e.g., from an SMT-LIBv2 define-sort). | |
SortType | mkSort (const std::string &name, uint32_t flags=ExprManager::SORT_FLAG_NONE) |
Creates a new sort with the given name. | |
SortConstructorType | mkSortConstructor (const std::string &name, size_t arity) |
Creates a new sort constructor with the given name and arity. | |
SortType | mkUnresolvedType (const std::string &name) |
Creates a new "unresolved type," used only during parsing. | |
SortConstructorType | mkUnresolvedTypeConstructor (const std::string &name, size_t arity) |
Creates a new unresolved (parameterized) type constructor of the given arity. | |
SortConstructorType | mkUnresolvedTypeConstructor (const std::string &name, const std::vector< Type > ¶ms) |
Creates a new unresolved (parameterized) type constructor given the type parameters. | |
bool | isUnresolvedType (const std::string &name) |
Returns true IFF name is an unresolved type. | |
std::vector< DatatypeType > | mkMutualDatatypeTypes (const std::vector< Datatype > &datatypes) |
Create sorts of mutually-recursive datatypes. | |
void | addOperator (Kind kind) |
Add an operator to the current legal set. | |
void | preemptCommand (Command *cmd) |
Preempt the next returned command with other ones; used to support the :named attribute in SMT-LIBv2, which implicitly inserts a new command before the current one. | |
bool | isBoolean (const std::string &name) |
Is the symbol bound to a boolean variable? | |
bool | isFunctionLike (const std::string &name) |
Is the symbol bound to a function (or function-like thing)? | |
bool | isDefinedFunction (const std::string &name) |
Is the symbol bound to a defined function? | |
bool | isDefinedFunction (Expr func) |
Is the Expr a defined function? | |
bool | isPredicate (const std::string &name) |
Is the symbol bound to a predicate? | |
Command * | nextCommand () throw (ParserException) |
Parse and return the next command. | |
Expr | nextExpression () throw (ParserException) |
Parse and return the next expression. | |
void | warning (const std::string &msg) |
Issue a warning to the user. | |
void | attributeNotSupported (const std::string &attr) |
Issue a warning to the user, but only once per attribute. | |
void | parseError (const std::string &msg) throw (ParserException) |
Raise a parse error with the given message. | |
void | unexpectedEOF (const std::string &msg) throw (ParserException) |
Unexpectedly encountered an EOF. | |
void | unimplementedFeature (const std::string &msg) throw (ParserException) |
If we are parsing only, don't raise an exception; if we are not, raise a parse error with the given message. | |
size_t | scopeLevel () const |
Gets the current declaration level. | |
void | pushScope (bool bindingLevel=false) |
void | popScope () |
void | useDeclarationsFrom (Parser *parser) |
Set the current symbol table used by this parser. | |
void | useDeclarationsFrom (SymbolTable *symtab) |
SymbolTable * | getSymbolTable () const |
Protected Member Functions | |
Parser (ExprManager *exprManager, Input *input, bool strictMode=false, bool parseOnly=false) | |
Create a parser state. | |
Friends | |
class | ParserBuilder |
This class encapsulates all of the state of a parser, including the name of the file, line number and column information, and in-scope declarations.
|
protected |
Create a parser state.
exprManager | the expression manager to use when creating expressions |
input | the parser input |
strictMode | whether to incorporate strict(er) compliance checks |
parseOnly | whether we are parsing only (and therefore certain checks need not be performed, like those about unimplemented features, |
void CVC4::parser::Parser::addOperator | ( | Kind | kind | ) |
Add an operator to the current legal set.
kind | the built-in operator to add |
void CVC4::parser::Parser::attributeNotSupported | ( | const std::string & | attr | ) |
Issue a warning to the user, but only once per attribute.
void CVC4::parser::Parser::checkArity | ( | Kind | kind, | |||
unsigned | numArgs ) | |||||
throw | ( | ParserException ) |
Check that kind
can accept numArgs
arguments.
kind | the built-in operator to check |
numArgs | the number of actual arguments |
ParserException | if checks are enabled and the operator kind cannot be applied to numArgs arguments. |
void CVC4::parser::Parser::checkDeclaration | ( | const std::string & | name, | |||
DeclarationCheck | check, | |||||
SymbolType | type = SYM_VARIABLE, | |||||
std::string | notes = "" ) | |||||
throw | ( | ParserException ) |
Checks if the declaration policy we want to enforce holds for the given symbol.
name | the symbol to check |
check | the kind of check to perform |
type | the type of the symbol |
notes | notes to add to a parse error (if one is generated) |
ParserException | if checks are enabled and the check fails |
void CVC4::parser::Parser::checkFunctionLike | ( | const std::string & | name | ) | ||
throw | ( | ParserException ) |
Checks whether the given name is bound to a function.
name | the name to check |
ParserException | if checks are enabled and name is not bound to a function |
void CVC4::parser::Parser::checkOperator | ( | Kind | kind, | |||
unsigned | numArgs ) | |||||
throw | ( | ParserException ) |
Check that kind
is a legal operator in the current logic and that it can accept numArgs
arguments.
kind | the built-in operator to check |
numArgs | the number of actual arguments |
ParserException | if the parser mode is strict and the operator kind has not been enabled |
void CVC4::parser::Parser::defineFunction | ( | const std::string & | name, |
const Expr & | val, | ||
bool | levelZero = false ) |
Create a new function definition (e.g., from a define-fun).
void CVC4::parser::Parser::defineParameterizedType | ( | const std::string & | name, |
const std::vector< Type > & | params, | ||
const Type & | type ) |
Create a new type definition (e.g., from an SMT-LIBv2 define-sort).
void CVC4::parser::Parser::defineType | ( | const std::string & | name, |
const std::vector< Type > & | params, | ||
const Type & | type ) |
Create a new (parameterized) type definition.
void CVC4::parser::Parser::defineType | ( | const std::string & | name, |
const Type & | type ) |
Create a new type definition.
void CVC4::parser::Parser::defineVar | ( | const std::string & | name, |
const Expr & | val, | ||
bool | levelZero = false ) |
Create a new variable definition (e.g., from a let binding).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
size_t CVC4::parser::Parser::getArity | ( | const std::string & | sort_name | ) |
Returns arity of a (parameterized) sort, given a name and args.
|
inline |
Get the associated ExprManager
.
|
inline |
Expr CVC4::parser::Parser::getFunction | ( | const std::string & | name | ) |
Returns a function, given a name.
name | the name of the variable |
|
inline |
Type CVC4::parser::Parser::getSort | ( | const std::string & | sort_name | ) |
Returns a sort, given a name.
sort_name | the name to look up |
Type CVC4::parser::Parser::getSort | ( | const std::string & | sort_name, |
const std::vector< Type > & | params ) |
Returns a (parameterized) sort, given a name and args.
|
inline |
Type CVC4::parser::Parser::getType | ( | const std::string & | var_name, |
SymbolType | type = SYM_VARIABLE ) |
Returns the type for the variable with the given name.
var_name | the symbol to lookup |
type | the (namespace) type of the symbol |
Expr CVC4::parser::Parser::getVariable | ( | const std::string & | name | ) |
Returns a variable, given a name.
name | the name of the variable |
bool CVC4::parser::Parser::isBoolean | ( | const std::string & | name | ) |
Is the symbol bound to a boolean variable?
bool CVC4::parser::Parser::isDeclared | ( | const std::string & | name, |
SymbolType | type = SYM_VARIABLE ) |
Checks if a symbol has been declared.
name | the symbol name |
type | the symbol type |
bool CVC4::parser::Parser::isDefinedFunction | ( | const std::string & | name | ) |
Is the symbol bound to a defined function?
bool CVC4::parser::Parser::isFunctionLike | ( | const std::string & | name | ) |
Is the symbol bound to a function (or function-like thing)?
bool CVC4::parser::Parser::isPredicate | ( | const std::string & | name | ) |
Is the symbol bound to a predicate?
bool CVC4::parser::Parser::isUnresolvedType | ( | const std::string & | name | ) |
Returns true IFF name is an unresolved type.
|
inlinevirtual |
Expr CVC4::parser::Parser::mkAnonymousFunction | ( | const std::string & | prefix, |
const Type & | type, | ||
uint32_t | flags = ExprManager::VAR_FLAG_NONE ) |
Create a new CVC4 function expression of the given type, appending a unique index to its name.
(That's the ONLY difference between mkAnonymousFunction() and mkFunction()).
Create a new CVC4 bound variable expression of the given type.
std::vector< Expr > CVC4::parser::Parser::mkBoundVars | ( | const std::vector< std::string > | names, |
const Type & | type ) |
Create a set of new CVC4 bound variable expressions of the given type.
Expr CVC4::parser::Parser::mkFunction | ( | const std::string & | name, |
const Type & | type, | ||
uint32_t | flags = ExprManager::VAR_FLAG_NONE ) |
Create a new CVC4 function expression of the given type.
std::vector< DatatypeType > CVC4::parser::Parser::mkMutualDatatypeTypes | ( | const std::vector< Datatype > & | datatypes | ) |
Create sorts of mutually-recursive datatypes.
SortType CVC4::parser::Parser::mkSort | ( | const std::string & | name, |
uint32_t | flags = ExprManager::SORT_FLAG_NONE ) |
Creates a new sort with the given name.
SortConstructorType CVC4::parser::Parser::mkSortConstructor | ( | const std::string & | name, |
size_t | arity ) |
Creates a new sort constructor with the given name and arity.
SortType CVC4::parser::Parser::mkUnresolvedType | ( | const std::string & | name | ) |
Creates a new "unresolved type," used only during parsing.
SortConstructorType CVC4::parser::Parser::mkUnresolvedTypeConstructor | ( | const std::string & | name, |
const std::vector< Type > & | params ) |
Creates a new unresolved (parameterized) type constructor given the type parameters.
SortConstructorType CVC4::parser::Parser::mkUnresolvedTypeConstructor | ( | const std::string & | name, |
size_t | arity ) |
Creates a new unresolved (parameterized) type constructor of the given arity.
Expr CVC4::parser::Parser::mkVar | ( | const std::string & | name, |
const Type & | type, | ||
uint32_t | flags = ExprManager::VAR_FLAG_NONE ) |
Create a new CVC4 variable expression of the given type.
std::vector< Expr > CVC4::parser::Parser::mkVars | ( | const std::vector< std::string > | names, |
const Type & | type, | ||
uint32_t | flags = ExprManager::VAR_FLAG_NONE ) |
Create a set of new CVC4 variable expressions of the given type.
Command * CVC4::parser::Parser::nextCommand | ( | ) | ||||
throw | ( | ParserException ) |
Parse and return the next command.
Expr CVC4::parser::Parser::nextExpression | ( | ) | ||||
throw | ( | ParserException ) |
Parse and return the next expression.
Referenced by CVC4::parser::Parser::ExprStream::nextExpr().
|
inline |
Raise a parse error with the given message.
Definition at line 515 of file parser.h.
References CVC4::parser::Input::parseError().
|
inline |
Definition at line 556 of file parser.h.
References CVC4::SymbolTable::popScope().
void CVC4::parser::Parser::preemptCommand | ( | Command * | cmd | ) |
Preempt the next returned command with other ones; used to support the :named attribute in SMT-LIBv2, which implicitly inserts a new command before the current one.
Also used in TPTP because function and predicate symbols are implicitly declared.
|
inline |
Definition at line 549 of file parser.h.
References CVC4::SymbolTable::pushScope().
void CVC4::parser::Parser::reserveSymbolAtAssertionLevel | ( | const std::string & | name | ) |
Reserve a symbol at the assertion level.
|
inline |
Gets the current declaration level.
Definition at line 547 of file parser.h.
References CVC4::SymbolTable::getLevel().
|
inline |
|
inline |
Deletes and replaces the current parser input.
Definition at line 235 of file parser.h.
References CVC4::parser::Input::setParser().
|
inline |
Unexpectedly encountered an EOF.
Definition at line 520 of file parser.h.
References CVC4::parser::Input::parseError().
|
inline |
If we are parsing only, don't raise an exception; if we are not, raise a parse error with the given message.
There is no actual parse error, everything is as expected, but we cannot create the Expr, Type, or other requested thing yet due to internal limitations. Even though it's not a parse error, we throw a parse error so that the input line and column information is available.
Think quantifiers. We don't have a TheoryQuantifiers yet, so we have no kind::FORALL or kind::EXISTS. But we might want to support parsing quantifiers (just not doing anything with them). So this mechanism gives you a way to do it with –parse-only.
|
inline |
Set the current symbol table used by this parser.
From now on, this parser will perform its definitions and lookups in the declaration scope of the "parser" argument (but doesn't re-delegate if the other parser's declaration scope changes later). A NULL argument restores this parser's "primordial" declaration scope assigned at its creation. Calling p->useDeclarationsFrom(p) is a no-op.
This feature is useful when e.g. reading out-of-band expression data:
However, the feature must be used carefully. Pushes and pops should be performed with the correct current declaration scope. Care must be taken to match up declaration scopes, of course; If variables in the deferred-to parser go out of scope, the secondary parser will give errors that they are undeclared. Also, an outer-scope variable shadowed by an inner-scope one of the same name may be temporarily inaccessible.
In short, caveat emptor.
|
inline |
|
inline |
Issue a warning to the user.
Definition at line 507 of file parser.h.
References CVC4::parser::Input::warning().
|
friend |