CVC4::parser::Parser Class Reference

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 > &params)
| 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 > &params, const Type &type)
| Create a new (parameterized) type definition.
void | 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).
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 > &params)
| 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

## Detailed Description

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.

Definition at line 106 of file parser.h.

## Constructor & Destructor Documentation

## Parser()

CVC4::parser::Parser::Parser | ( | ExprManager * | exprManager,
|  | Input * | input,
|  | bool | strictMode = false,
|  | bool | parseOnly = false )

protected

Create a parser state.

Attention
  The parser takes "ownership" of the given input and will delete it on destruction.

Parameters

  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,

See also
  unimplementedFeature())

## ~Parser()

virtual CVC4::parser::Parser::~Parser | ( |  | ) |

inlinevirtual

Definition at line 220 of file parser.h.

## Member Function Documentation

## addOperator()

void CVC4::parser::Parser::addOperator | ( | Kind | kind | ) |

Add an operator to the current legal set.

Parameters

  kind | the built-in operator to add

## allowIncludeFile()

void CVC4::parser::Parser::allowIncludeFile | ( |  | ) |

inline

Definition at line 271 of file parser.h.

## attributeNotSupported()

void CVC4::parser::Parser::attributeNotSupported | ( | const std::string & | attr | ) |

Issue a warning to the user, but only once per attribute.

## canIncludeFile()

bool CVC4::parser::Parser::canIncludeFile | ( |  | ) | const

inline

Definition at line 273 of file parser.h.

## checkArity()

void CVC4::parser::Parser::checkArity | ( | Kind | kind,
|  | unsigned | numArgs )
throw | ( | ParserException ) |  |  |

Check that `kind` can accept `numArgs` arguments.

Parameters

  kind | the built-in operator to check
  numArgs | the number of actual arguments

Exceptions

  ParserException | if checks are enabled and the operator `kind` cannot be applied to `numArgs` arguments.

## checkDeclaration()

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.

Parameters

  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)

Exceptions

  ParserException | if checks are enabled and the check fails

## checkFunctionLike()

void CVC4::parser::Parser::checkFunctionLike | ( | const std::string & | name | ) |
throw | ( | ParserException ) |  |  |

Checks whether the given name is bound to a function.

Parameters

  name | the name to check

Exceptions

  ParserException | if checks are enabled and name is not bound to a function

## checkOperator()

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.

Parameters

  kind | the built-in operator to check
  numArgs | the number of actual arguments

Exceptions

  ParserException | if the parser mode is strict and the operator `kind` has not been enabled

## defineFunction()

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).

## defineParameterizedType()

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).

## defineType() [1/2]

void CVC4::parser::Parser::defineType | ( | const std::string & | name,
|  | const std::vector< Type > & | params,
|  | const Type & | type )

Create a new (parameterized) type definition.

## defineType() [2/2]

void CVC4::parser::Parser::defineType | ( | const std::string & | name,
|  | const Type & | type )

Create a new type definition.

## defineVar()

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).

## disableChecks()

void CVC4::parser::Parser::disableChecks | ( |  | ) |

inline

Disable semantic checks during parsing.

Disabling checks may lead to crashes on bad inputs.

Definition at line 260 of file parser.h.

## disableStrictMode()

void CVC4::parser::Parser::disableStrictMode | ( |  | ) |

inline

Disable strict parsing.

Allows certain syntactic infelicities to pass without comment.

Definition at line 267 of file parser.h.

## disallowIncludeFile()

void CVC4::parser::Parser::disallowIncludeFile | ( |  | ) |

inline

Definition at line 272 of file parser.h.

## done()

bool CVC4::parser::Parser::done | ( |  | ) | const

inline

Check if we are done – either the end of input has been reached, or some error has been encountered.

Returns
  true if parser is done

Definition at line 247 of file parser.h.

## enableChecks()

void CVC4::parser::Parser::enableChecks | ( |  | ) |

inline

Enable semantic checks during parsing.

Definition at line 257 of file parser.h.

## enableStrictMode()

void CVC4::parser::Parser::enableStrictMode | ( |  | ) |

inline

Enable strict parsing, according to the language standards.

Definition at line 263 of file parser.h.

## forceLogic()

void CVC4::parser::Parser::forceLogic | ( | const std::string & | logic | ) |

inline

Definition at line 279 of file parser.h.

## getArity()

size_t CVC4::parser::Parser::getArity | ( | const std::string & | sort_name | ) |

Returns arity of a (parameterized) sort, given a name and args.

## getExprManager()

ExprManager * CVC4::parser::Parser::getExprManager | ( |  | ) | const

inline

Get the associated `ExprManager`.

Definition at line 225 of file parser.h.

## getForcedLogic()

const std::string & CVC4::parser::Parser::getForcedLogic | ( |  | ) | const

inline

Definition at line 280 of file parser.h.

## getFunction()

Expr CVC4::parser::Parser::getFunction | ( | const std::string & | name | ) |

Returns a function, given a name.

Parameters

  name | the name of the variable

Returns
  the variable expression

## getInput()

Input * CVC4::parser::Parser::getInput | ( |  | ) | const

inline

Get the associated input.

Definition at line 230 of file parser.h.

## getSort() [1/2]

Type CVC4::parser::Parser::getSort | ( | const std::string & | sort_name | ) |

Returns a sort, given a name.

Parameters

  sort_name | the name to look up

## getSort() [2/2]

Type CVC4::parser::Parser::getSort | ( | const std::string & | sort_name,
|  | const std::vector< Type > & | params )

Returns a (parameterized) sort, given a name and args.

## getSymbolTable()

SymbolTable * CVC4::parser::Parser::getSymbolTable | ( |  | ) | const

inline

Definition at line 601 of file parser.h.

## getType()

Type CVC4::parser::Parser::getType | ( | const std::string & | var_name,
|  | SymbolType | type = SYM_VARIABLE )

Returns the type for the variable with the given name.

Parameters

  var_name | the symbol to lookup
  type | the (namespace) type of the symbol

## getVariable()

Expr CVC4::parser::Parser::getVariable | ( | const std::string & | name | ) |

Returns a variable, given a name.

Parameters

  name | the name of the variable

Returns
  the variable expression

## isBoolean()

bool CVC4::parser::Parser::isBoolean | ( | const std::string & | name | ) |

Is the symbol bound to a boolean variable?

## isDeclared()

bool CVC4::parser::Parser::isDeclared | ( | const std::string & | name,
|  | SymbolType | type = SYM_VARIABLE )

Checks if a symbol has been declared.

Parameters

  name | the symbol name
  type | the symbol type

Returns
  true iff the symbol has been declared with the given type

## isDefinedFunction() [1/2]

bool CVC4::parser::Parser::isDefinedFunction | ( | const std::string & | name | ) |

Is the symbol bound to a defined function?

## isDefinedFunction() [2/2]

bool CVC4::parser::Parser::isDefinedFunction | ( | Expr | func | ) |

Is the Expr a defined function?

## isFunctionLike()

bool CVC4::parser::Parser::isFunctionLike | ( | const std::string & | name | ) |

Is the symbol bound to a function (or function-like thing)?

## isPredicate()

bool CVC4::parser::Parser::isPredicate | ( | const std::string & | name | ) |

Is the symbol bound to a predicate?

## isUnresolvedType()

bool CVC4::parser::Parser::isUnresolvedType | ( | const std::string & | name | ) |

Returns true IFF name is an unresolved type.

## logicIsForced()

bool CVC4::parser::Parser::logicIsForced | ( |  | ) | const

inline

Definition at line 281 of file parser.h.

## logicIsSet()

virtual bool CVC4::parser::Parser::logicIsSet | ( |  | ) |

inlinevirtual

Expose the functionality from SMT/SMT2 parsers, while making implementation optional by returning false by default.

Definition at line 277 of file parser.h.

## mkAnonymousFunction()

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()).

## mkBoundVar()

Expr CVC4::parser::Parser::mkBoundVar | ( | const std::string & | name,
|  | const Type & | type )

Create a new CVC4 bound variable expression of the given type.

## mkBoundVars()

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.

## mkFunction()

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.

## mkMutualDatatypeTypes()

std::vector< DatatypeType > CVC4::parser::Parser::mkMutualDatatypeTypes | ( | const std::vector< Datatype > & | datatypes | ) |

Create sorts of mutually-recursive datatypes.

## mkSort()

SortType CVC4::parser::Parser::mkSort | ( | const std::string & | name,
|  | uint32_t | flags = ExprManager::SORT_FLAG_NONE )

Creates a new sort with the given name.

## mkSortConstructor()

SortConstructorType CVC4::parser::Parser::mkSortConstructor | ( | const std::string & | name,
|  | size_t | arity )

Creates a new sort constructor with the given name and arity.

## mkUnresolvedType()

SortType CVC4::parser::Parser::mkUnresolvedType | ( | const std::string & | name | ) |

Creates a new "unresolved type," used only during parsing.

## mkUnresolvedTypeConstructor() [1/2]

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.

## mkUnresolvedTypeConstructor() [2/2]

SortConstructorType CVC4::parser::Parser::mkUnresolvedTypeConstructor | ( | const std::string & | name,
|  | size_t | arity )

Creates a new unresolved (parameterized) type constructor of the given arity.

## mkVar()

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.

## mkVars()

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.

## nextCommand()

Command * CVC4::parser::Parser::nextCommand | ( |  | ) |
throw | ( | ParserException ) |  |  |

Parse and return the next command.

## nextExpression()

Expr CVC4::parser::Parser::nextExpression | ( |  | ) |
throw | ( | ParserException ) |  |  |

Parse and return the next expression.

Referenced by CVC4::parser::Parser::ExprStream::nextExpr().

## parseError()

void CVC4::parser::Parser::parseError | ( | const std::string & | msg | ) |
throw | ( | ParserException ) |  |  |

inline

Raise a parse error with the given message.

Definition at line 515 of file parser.h.

References CVC4::parser::Input::parseError().

## popScope()

void CVC4::parser::Parser::popScope | ( |  | ) |

inline

Definition at line 556 of file parser.h.

References CVC4::SymbolTable::popScope().

## preemptCommand()

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.

## pushScope()

void CVC4::parser::Parser::pushScope | ( | bool | bindingLevel = false | ) |

inline

Definition at line 549 of file parser.h.

References CVC4::SymbolTable::pushScope().

## reserveSymbolAtAssertionLevel()

void CVC4::parser::Parser::reserveSymbolAtAssertionLevel | ( | const std::string & | name | ) |

Reserve a symbol at the assertion level.

## scopeLevel()

size_t CVC4::parser::Parser::scopeLevel | ( |  | ) | const

inline

Gets the current declaration level.

Definition at line 547 of file parser.h.

References CVC4::SymbolTable::getLevel().

## setDone()

void CVC4::parser::Parser::setDone | ( | bool | done = true | ) |

inline

Sets the done flag.

Definition at line 252 of file parser.h.

## setInput()

void CVC4::parser::Parser::setInput | ( | Input * | input | ) |

inline

Deletes and replaces the current parser input.

Definition at line 235 of file parser.h.

References CVC4::parser::Input::setParser().

## strictModeEnabled()

bool CVC4::parser::Parser::strictModeEnabled | ( |  | ) |

inline

Definition at line 269 of file parser.h.

## unexpectedEOF()

void CVC4::parser::Parser::unexpectedEOF | ( | const std::string & | msg | ) |
throw | ( | ParserException ) |  |  |

inline

Unexpectedly encountered an EOF.

Definition at line 520 of file parser.h.

References CVC4::parser::Input::parseError().

## unimplementedFeature()

void CVC4::parser::Parser::unimplementedFeature | ( | const std::string & | msg | ) |
throw | ( | ParserException ) |  |  |

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.

Definition at line 538 of file parser.h.

## useDeclarationsFrom() [1/2]

void CVC4::parser::Parser::useDeclarationsFrom | ( | Parser * | parser | ) |

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:

1. Parsing –replay log files produced with –replay-log.
2. Perhaps a multi-query benchmark file is being single-stepped with intervening queries on stdin that must reference the same declaration scope(s).

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.

Definition at line 589 of file parser.h.

## useDeclarationsFrom() [2/2]

void CVC4::parser::Parser::useDeclarationsFrom | ( | SymbolTable * | symtab | ) |

inline

Definition at line 597 of file parser.h.

## warning()

void CVC4::parser::Parser::warning | ( | const std::string & | msg | ) |

inline

Issue a warning to the user.

Definition at line 507 of file parser.h.

References CVC4::parser::Input::warning().

## Friends And Related Symbol Documentation

## ParserBuilder

friend class ParserBuilder

friend

Definition at line 107 of file parser.h.

The documentation for this class was generated from the following file:

- src/parser/parser.h