mirror of
https://github.com/Z3Prover/z3
synced 2025-05-03 22:05:45 +00:00
add facility for incremental parsing #6123
Adding new API object to maintain state between calls to parser. The state is incremental: all declarations of sorts and functions are valid in the next parse. The parser produces an ast-vector of assertions that are parsed in the current calls. The following is a unit test: ``` from z3 import * pc = ParserContext() A = DeclareSort('A') pc.add_sort(A) print(pc.from_string("(declare-const x A) (declare-const y A) (assert (= x y))")) print(pc.from_string("(declare-const z A) (assert (= x z))")) print(parse_smt2_string("(declare-const x Int) (declare-const y Int) (assert (= x y))")) s = Solver() s.from_string("(declare-sort A)") s.from_string("(declare-const x A)") s.from_string("(declare-const y A)") s.from_string("(assert (= x y))") print(s.assertions()) s.from_string("(declare-const z A)") print(s.assertions()) s.from_string("(assert (= x z))") print(s.assertions()) ``` It produces results of the form ``` [x == y] [x == z] [x == y] [x == y] [x == y] [x == y, x == z] ``` Thus, the set of assertions returned by a parse call is just the set of assertions added. The solver maintains state between parser calls so that declarations made in a previous call are still available when declaring the constant 'z'. The same holds for the parser_context_from_string function: function and sort declarations either added externally or declared using SMTLIB2 command line format as strings are valid for later calls.
This commit is contained in:
parent
8c2ba3d47e
commit
815518dc02
8 changed files with 235 additions and 73 deletions
|
@ -20,6 +20,7 @@ DEFINE_TYPE(Z3_constructor);
|
|||
DEFINE_TYPE(Z3_constructor_list);
|
||||
DEFINE_TYPE(Z3_params);
|
||||
DEFINE_TYPE(Z3_param_descrs);
|
||||
DEFINE_TYPE(Z3_parser_context);
|
||||
DEFINE_TYPE(Z3_goal);
|
||||
DEFINE_TYPE(Z3_tactic);
|
||||
DEFINE_TYPE(Z3_probe);
|
||||
|
@ -58,6 +59,7 @@ DEFINE_TYPE(Z3_rcf_num);
|
|||
- \c Z3_constructor_list: list of constructors for a (recursive) datatype.
|
||||
- \c Z3_params: parameter set used to configure many components such as: simplifiers, tactics, solvers, etc.
|
||||
- \c Z3_param_descrs: provides a collection of parameter names, their types, default values and documentation strings. Solvers, tactics, and other objects accept different collection of parameters.
|
||||
- \c Z3_parser_context: context for incrementally parsing strings. Declarations can be added incrementally to the parser state.
|
||||
- \c Z3_model: model for the constraints asserted into the logical context.
|
||||
- \c Z3_func_interp: interpretation of a function in a model.
|
||||
- \c Z3_func_entry: representation of the value of a \c Z3_func_interp at a particular point.
|
||||
|
@ -1413,6 +1415,7 @@ typedef enum
|
|||
def_Type('CONSTRUCTOR_LIST', 'Z3_constructor_list', 'ConstructorList')
|
||||
def_Type('SOLVER', 'Z3_solver', 'SolverObj')
|
||||
def_Type('SOLVER_CALLBACK', 'Z3_solver_callback', 'SolverCallbackObj')
|
||||
def_Type('PARSER_CONTEXT', 'Z3_parser_context', 'ParserContextObj')
|
||||
def_Type('GOAL', 'Z3_goal', 'GoalObj')
|
||||
def_Type('TACTIC', 'Z3_tactic', 'TacticObj')
|
||||
def_Type('PARAMS', 'Z3_params', 'Params')
|
||||
|
@ -5827,6 +5830,55 @@ extern "C" {
|
|||
|
||||
Z3_string Z3_API Z3_eval_smtlib2_string(Z3_context, Z3_string str);
|
||||
|
||||
|
||||
/**
|
||||
\brief Create a parser context.
|
||||
|
||||
A parser context maintains state between calls to \c Z3_parser_context_parse_string
|
||||
where the caller can pass in a set of SMTLIB2 commands.
|
||||
It maintains all the declarations from previous calls together with
|
||||
of sorts and function declarations (including 0-ary) that are added directly to the context.
|
||||
|
||||
def_API('Z3_mk_parser_context', PARSER_CONTEXT, (_in(CONTEXT),))
|
||||
*/
|
||||
Z3_parser_context Z3_API Z3_mk_parser_context(Z3_context c);
|
||||
|
||||
/**
|
||||
\brief Increment the reference counter of the given \c Z3_parser_context object.
|
||||
|
||||
def_API('Z3_parser_context_inc_ref', VOID, (_in(CONTEXT), _in(PARSER_CONTEXT)))
|
||||
*/
|
||||
void Z3_API Z3_parser_context_inc_ref(Z3_context c, Z3_parser_context pc);
|
||||
|
||||
/**
|
||||
\brief Decrement the reference counter of the given \c Z3_parser_context object.
|
||||
|
||||
def_API('Z3_parser_context_dec_ref', VOID, (_in(CONTEXT), _in(PARSER_CONTEXT)))
|
||||
*/
|
||||
void Z3_API Z3_parser_context_dec_ref(Z3_context c, Z3_parser_context pc);
|
||||
|
||||
/**
|
||||
\brief Add a sort declaration.
|
||||
|
||||
def_API('Z3_parser_context_add_sort', VOID, (_in(CONTEXT), _in(PARSER_CONTEXT), _in(SORT)))
|
||||
*/
|
||||
void Z3_API Z3_parser_context_add_sort(Z3_context c, Z3_parser_context pc, Z3_sort s);
|
||||
|
||||
/**
|
||||
\brief Add a function declaration.
|
||||
|
||||
def_API('Z3_parser_context_add_decl', VOID, (_in(CONTEXT), _in(PARSER_CONTEXT), _in(FUNC_DECL)))
|
||||
*/
|
||||
void Z3_API Z3_parser_context_add_decl(Z3_context c, Z3_parser_context pc, Z3_func_decl f);
|
||||
|
||||
/**
|
||||
\brief Parse a string of SMTLIB2 commands. Return assertions.
|
||||
|
||||
def_API('Z3_parser_context_from_string', AST_VECTOR, (_in(CONTEXT), _in(PARSER_CONTEXT), _in(STRING)))
|
||||
*/
|
||||
Z3_ast_vector Z3_API Z3_parser_context_from_string(Z3_context c, Z3_parser_context pc, Z3_string s);
|
||||
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** @name Error Handling */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue