7#include "dlinear/parser/smt2/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"
26 Smt2Parser parser(*
this);
28 const bool res = parser.parse() == 0;
33void Smt2Driver::error(
const location &l,
const std::string &m) { std::cerr << l <<
" : " << m << std::endl; }
68std::string Smt2Driver::MakeUniqueName(
const std::string &name) {
69 std::stringstream oss;
85 for (
const auto &term : term_list) {
87 std::string value_str;
91 switch (term.type()) {
92 case Term::Type::EXPRESSION: {
98 value_str = (std::stringstream{} << iv).str();
101 case Term::Type::FORMULA: {
102 const Formula &f{term.formula()};
105 if (is_variable(f)) {
106 value_str = box[get_variable(f)].ub() == 1 ?
"true" :
"false";
108 DLINEAR_RUNTIME_ERROR_FMT(
"get-value does not handle a compound formula {}.", term_str);
123 DLINEAR_OUT_OF_RANGE_FMT(
"{} is an undeclared name.", name);
128 if (it ==
scope_constants_.cend()) DLINEAR_OUT_OF_RANGE_FMT(
"{} is an undeclared constant.", name);
134 if (it ==
scope_variables_.cend()) DLINEAR_OUT_OF_RANGE_FMT(
"{} is an undeclared variable.", name);
140 if (it ==
scope_functions_.end()) DLINEAR_OUT_OF_RANGE_FMT(
"Function {} is not defined.", name);
141 return it->second(arguments);
145 DLINEAR_ASSERT(is_constant(value),
"Value must be a constant expression.");
Collection of variables with associated intervals.
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...
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 SMT2 language using the define-fun command.
Smt2Scanner * scanner_
The scanner producing the tokens for the parser.
const Variable & LookupVariable(const std::string &name) const
Lookup a variable associated with a name name.
void DefineLocalConstant(const std::string &name, const Expression &value)
Define a constant within the current scope.
bool ParseStreamCore(std::istream &in) override
Parse the stream.
Variable RegisterVariable(const std::string &name, Sort sort)
Register a variable with name name and sort s in the scope.
ScopedUnorderedMap< std::string, Expression > scope_constants_
Scoped map from a name to a constant.
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.
ScopedUnorderedMap< std::string, FunctionDefinition > scope_functions_
Scoped map from a name to a Function.
Smt2Driver(Context &context)
construct a new parser driver context
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.
Variable DeclareVariable(const std::string &name, Sort sort)
Declare a variable with name name and sort sort.
void GetValue(const std::vector< Term > &term_list) const
Get the value of all the terms in term_list.
static Formula EliminateBooleanVariables(const Variables &vars, const Formula &f)
Eliminate Boolean variables vars from f.
int64_t nextUniqueId_
Sequential value concatenated to names to make them unique.
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.
Smt2Scanner * scanner()
Pointer to the current scanner instance, this is used to connect the parser to the scanner.
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.
const Expression & LookupConstant(const std::string &name) const
Lookup a constant expression associated with a name name.
std::variant< const Expression *, const Variable * > LookupDefinedName(const std::string &name) const
Lookup a variable or constant expression associated with a name name.
Smt2Scanner 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.
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.
Namespace for the SMT2 parser of the dlinear library.
Variable::Type SortToType(Sort sort)
Convert a sort to a variable type.