7#include "dlinear/parser/vnnlib/Driver.h"
12#include "dlinear/symbolic/ExpressionEvaluator.h"
13#include "dlinear/symbolic/PrefixPrinter.h"
14#include "dlinear/util/exception.h"
15#include "dlinear/util/logging.h"
28 VnnlibParser parser(*
this);
30 const bool res = parser.parse() == 0;
35void VnnlibDriver::error(
const location &l,
const std::string &m) { std::cerr << l <<
" : " << m << std::endl; }
72std::string VnnlibDriver::MakeUniqueName(
const std::string &name) {
73 std::stringstream oss;
89 for (
const auto &term : term_list) {
91 std::string value_str;
95 switch (term.type()) {
96 case Term::Type::EXPRESSION: {
102 value_str = (std::stringstream{} << iv).str();
105 case Term::Type::FORMULA: {
106 const Formula &f{term.formula()};
109 if (is_variable(f)) {
110 value_str = box[get_variable(f)].ub() == 1 ?
"true" :
"false";
112 DLINEAR_RUNTIME_ERROR_FMT(
"get-value does not handle a compound formula {}.", term_str);
127 DLINEAR_OUT_OF_RANGE_FMT(
"{} is an undeclared name.", name);
132 if (it ==
scope_constants_.cend()) DLINEAR_OUT_OF_RANGE_FMT(
"{} is an undeclared constant.", name);
138 if (it ==
scope_variables_.cend()) DLINEAR_OUT_OF_RANGE_FMT(
"{} is an undeclared variable.", name);
144 if (it ==
scope_functions_.end()) DLINEAR_OUT_OF_RANGE_FMT(
"Function {} is not defined.", name);
145 return it->second(arguments);
149 DLINEAR_ASSERT(is_constant(value),
"Value must be a constant expression.");
Collection of variables with associated intervals.
const std::vector< Variable > & variables() const
Get read-only access to the variables of the box.
const bool & silent() const
Get read-write access to the silent parameter of the configuration.
Context class that holds the set of constraints and provide Assert/Push/Pop/CheckSat functionalities.
const Config & config() const
Get read-only access to the configuration of the context.
void DeclareVariable(const Variable &v, bool is_model_variable=true)
Declare a variable v.
const Box & model() const
Get a representation of a model computed by the solver in response to the last invocation of the chec...
const Box & box() const
Get the current active box from the top of the stack of boxes.
The Driver is the base class for all the parsers.
bool debug_scanning_
Enable debug output in the flex scanner.
bool debug_parsing_
Enable debug output in the bison parser.
Context & context_
The context filled during parsing of the expressions.
Evaluate an expression with a given box.
Print expressions and formulas in prefix-form.
Represents a symbolic form of an expression.
Represents a symbolic variable.
@ BOOLEAN
A BOOLEAN variable takes a bool value.
Represents a set of variables.
A new function defined by the user in the VNNLIB language using the define-fun command.
Generic term that can be either an expression or a formula.
const Expression & expression() const
Get read-only access to the expression of the term.
static Formula EliminateBooleanVariables(const Variables &vars, const Formula &f)
Eliminate Boolean variables vars from f.
ScopedUnorderedMap< std::string, Expression > scope_constants_
Scoped map from a name to a constant.
Variable DeclareLocalVariable(const std::string &name, Sort sort)
Declare a new variable with label name that is globally unique and cannot occur in an SMT-LIBv2 file.
const Expression & LookupConstant(const std::string &name) const
Lookup a constant expression associated with a name name.
VnnlibScanner * scanner()
Pointer to the current scanner instance, this is used to connect the parser to the scanner.
int64_t nextUniqueId_
Sequential value concatenated to names to make them unique.
bool ParseStreamCore(std::istream &in) override
Parse the stream.
void DefineFun(const std::string &name, const std::vector< Variable > ¶meters, Sort return_type, const Term &body)
Called by the define-fun command in the SMT-2 file.
const Variable & LookupVariable(const std::string &name) const
Lookup a variable associated with a name name.
Term LookupFunction(const std::string &name, const std::vector< Term > &arguments) const
Lookup a function with name name and run it with arguments, producing a new term.
Variable DeclareVariable(const std::string &name, Sort sort)
Declare a variable with name name and sort sort.
static void error(const location &l, const std::string &m)
Error handling with associated line number.
ScopedUnorderedMap< std::string, Variable > scope_variables_
Scoped map from a name to a Variable.
std::variant< const Expression *, const Variable * > LookupDefinedName(const std::string &name) const
Lookup a variable or constant expression associated with a name name.
void DefineLocalConstant(const std::string &name, const Expression &value)
Define a constant within the current scope.
VnnlibScanner * scanner_
The scanner producing the tokens for the parser.
ScopedUnorderedMap< std::string, FunctionDefinition > scope_functions_
Scoped map from a name to a Function.
Variable RegisterVariable(const std::string &name, Sort sort)
Register a variable with name name and sort s in the scope.
VnnlibDriver(Context &context)
construct a new parser driver context
void GetValue(const std::vector< Term > &term_list) const
Get the value of all the terms in term_list.
VnnlibScanner is a derived class to add some extra function to the scanner class.
void set_debug(bool b)
Enable debug output (via arg_yyout) if compiled into the scanner.
Namespace for the VNNLIB parser of the dlinear library.
Variable::Type SortToType(Sort sort)
Convert a sort to a variable type.