question(C/C++ API examples): string to expression conversion on traversing AST #5151
-
Maybe I misinterpret the C and C++ API, but I could not find a way to add functions to be later filled with simple expressions, ie when traversing an AST via Visitor pattern for renaming etc according to stongest postcondition (+LBE). Say we have
My understanding how to parse expressions from strings looks roughly like the following:
context c;
sort_vector sorts(c);
func_decl_vector decls(c);
std::map<std::string, sort> varmap;
varmap.emplace("b", c.bool_sort());
decls.push_back(c.function("a", 0, 0, varmap["b"]));
expr_vector a = c.parse_string("(assert a)", sorts, decls); Does this mean that
Any example how to efficiently traverse a simple AST would be appreciated. From what I understand, I must reverse the AST to apply visitor on an according bottom-up representation or keep explicitly track or dump everything into a string and rename it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
After tinkering around, I think collecting everything and dumping a string is easier. Would be great, if documentation would be more explicit about how to do dynamic stuff. I dont understand the design decision to require Lisp-like strings and then not offer an according AST-API. |
Beta Was this translation helpful? Give feedback.
-
I have not fully understood the questions and comments in the post yet so find it somewhat difficult to answer. SMTLIB2 is a standard format for exchanging benchmarks. Z3 supports this format and exposes parsers for benchmarks in this format. Expression parsing can be built in an indirect way using these commands, but it isn't first class.
The main message of the example is that there are functions to test the kind of the expression and to get immediate sub-expressions. |
Beta Was this translation helpful? Give feedback.
I have not fully understood the questions and comments in the post yet so find it somewhat difficult to answer.
It seems there are different expectations.
SMTLIB2 is a standard format for exchanging benchmarks. Z3 supports this format and exposes parsers for benchmarks in this format.
The basic structure of and SMTLIB2 benchmark is a sequence of commands. Each command has an effect on a solver state.
We therefore expose SMTLIB2 parsers for solver objects.
Expression parsing can be built in an indirect way using these commands, but it isn't first class.
I have heard before that users somehow want to create expression strings and parse them into objects, but the need to serialize in and out…