dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
Driver.h
1
12#pragma once
13
14#include <istream>
15#include <string>
16#include <utility>
17#include <variant>
18#include <vector>
19
20#include "dlinear/parser/Driver.h"
21#include "dlinear/parser/vnnlib/FunctionDefinition.h"
22#include "dlinear/parser/vnnlib/Term.h"
23#include "dlinear/parser/vnnlib/scanner.h"
24#include "dlinear/solver/Context.h"
25#include "dlinear/util/ScopedUnorderedMap.hpp"
26
27namespace dlinear::vnnlib {
28
38class VnnlibDriver : public Driver {
39 public:
41 explicit VnnlibDriver(Context &context); // NOLINT(runtime/references): Reference context filled during parsing.
42
47 static void error(const location &l, const std::string &m);
48
49 bool ParseStreamCore(std::istream &in) override;
50
60 static Formula EliminateBooleanVariables(const Variables &vars, const Formula &f);
61
71 void DefineFun(const std::string &name, const std::vector<Variable> &parameters, Sort return_type, const Term &body);
72
77 Variable RegisterVariable(const std::string &name, Sort sort);
78
80 Variable DeclareVariable(const std::string &name, Sort sort);
81
83 void DeclareVariable(const std::string &name, Sort sort, const Term &lb, const Term &ub);
84
86 Variable DeclareLocalVariable(const std::string &name, Sort sort);
87
89 void DefineLocalConstant(const std::string &name, const Expression &value);
90
97 void GetValue(const std::vector<Term> &term_list) const;
98
105 std::variant<const Expression *, const Variable *> LookupDefinedName(const std::string &name) const;
112 const Expression &LookupConstant(const std::string &name) const;
119 const Variable &LookupVariable(const std::string &name) const;
128 Term LookupFunction(const std::string &name, const std::vector<Term> &arguments) const;
129
130 void PushScope() { scope_variables_.push(); }
131
132 void PopScope() { scope_variables_.pop(); }
133
134 std::string MakeUniqueName(const std::string &name);
135
141
142 private:
144
148
149 int64_t nextUniqueId_{};
150};
151
152} // namespace dlinear::vnnlib
Context class that holds the set of constraints and provide Assert/Push/Pop/CheckSat functionalities.
Definition Context.h:31
The Driver is the base class for all the parsers.
Definition Driver.h:26
const Context & context() const
Get read-only access to the enabled of the Driver.
Definition Driver.h:143
Represents a symbolic form of an expression.
Represents a symbolic form of a first-order logic formula.
Represents a symbolic variable.
Represents a set of variables.
Generic term that can be either an expression or a formula.
Definition Term.h:34
The VnnlibDriver class brings together all components.
Definition Driver.h:38
static Formula EliminateBooleanVariables(const Variables &vars, const Formula &f)
Eliminate Boolean variables vars from f.
Definition Driver.cpp:37
ScopedUnorderedMap< std::string, Expression > scope_constants_
Scoped map from a name to a constant.
Definition Driver.h:145
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.
Definition Driver.cpp:79
const Expression & LookupConstant(const std::string &name) const
Lookup a constant expression associated with a name name.
Definition Driver.cpp:130
VnnlibScanner * scanner()
Pointer to the current scanner instance, this is used to connect the parser to the scanner.
Definition Driver.h:140
int64_t nextUniqueId_
Sequential value concatenated to names to make them unique.
Definition Driver.h:149
bool ParseStreamCore(std::istream &in) override
Parse the stream.
Definition Driver.cpp:23
void DefineFun(const std::string &name, const std::vector< Variable > &parameters, Sort return_type, const Term &body)
Called by the define-fun command in the SMT-2 file.
Definition Driver.cpp:47
const Variable & LookupVariable(const std::string &name) const
Lookup a variable associated with a name name.
Definition Driver.cpp:136
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.
Definition Driver.cpp:142
Variable DeclareVariable(const std::string &name, Sort sort)
Declare a variable with name name and sort sort.
Definition Driver.cpp:61
static void error(const location &l, const std::string &m)
Error handling with associated line number.
Definition Driver.cpp:35
ScopedUnorderedMap< std::string, Variable > scope_variables_
Scoped map from a name to a Variable.
Definition Driver.h:146
std::variant< const Expression *, const Variable * > LookupDefinedName(const std::string &name) const
Lookup a variable or constant expression associated with a name name.
Definition Driver.cpp:122
void DefineLocalConstant(const std::string &name, const Expression &value)
Define a constant within the current scope.
Definition Driver.cpp:148
VnnlibScanner * scanner_
The scanner producing the tokens for the parser.
Definition Driver.h:143
ScopedUnorderedMap< std::string, FunctionDefinition > scope_functions_
Scoped map from a name to a Function.
Definition Driver.h:147
Variable RegisterVariable(const std::string &name, Sort sort)
Register a variable with name name and sort s in the scope.
Definition Driver.cpp:53
VnnlibDriver(Context &context)
construct a new parser driver context
Definition Driver.cpp:19
void GetValue(const std::vector< Term > &term_list) const
Get the value of all the terms in term_list.
Definition Driver.cpp:86
VnnlibScanner is a derived class to add some extra function to the scanner class.
Definition scanner.h:41
Namespace for the VNNLIB parser of the dlinear library.
Definition Driver.cpp:17
Sort
Sort of a term.
Definition Sort.h:18