mirror of
https://github.com/Z3Prover/z3
synced 2025-04-27 10:55:50 +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
|
@ -44,6 +44,7 @@ struct Z3_solver_ref : public api::object {
|
|||
params_ref m_params;
|
||||
symbol m_logic;
|
||||
scoped_ptr<solver2smt2_pp> m_pp;
|
||||
scoped_ptr<cmd_context> m_cmd_context;
|
||||
mutex m_mux;
|
||||
event_handler* m_eh;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue