简体   繁体   English

如何使用Z3 C ++ api读取smtlib2字符串?

[英]How to read smtlib2 strings using Z3 C++ api?

I want to create an expr object from a given SMTLIB2 file. 我想从给定的SMTLIB2文件创建一个expr对象。 I can see a Z3_parse_smtlib_string function in the C examples. 我可以在C示例中看到Z3_parse_smtlib_string函数。 Is there a wrapper for that in the expr class? expr类中是否有一个包装器?

The Z3 C++ API does not explicitly provide this functionality as part of the expr class. Z3 C ++ API没有明确地将此功能作为expr类的一部分提供。 However, the C++ API can be used alongside the C API, ie, the function Z3_parse_smtlib_string (or ... _file ) can be used to achieve this. 但是,C ++ API可以与C API一起使用,即,可以使用函数Z3_parse_smtlib_string (或... _file )来实现此目的。 Note that this function returns a Z3_ast , which must be converted to an expr object to get back to the C++ "world". 请注意,此函数返回Z3_ast ,必须将其转换为expr对象才能返回到C ++“world”。

A simple example: 一个简单的例子:

#include <z3++.h>

...

context ctx;
Z3_ast a = Z3_parse_smtlib2_file(ctx, "test.smt2", 0, 0, 0, 0, 0, 0);    
expr e(ctx, a);
std::cout << "Result = " << e << std::endl;

Since the Z3_parse_smtlib2_* functions do not perform error checking, no exception will be thrown upon errors. 由于Z3_parse_smtlib2_*函数不执行错误检查,因此在发生错误时不会引发异常。 This can be achieved by calls to context::check_error() . 这可以通过调用context::check_error()来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM