简体   繁体   English

将java布尔表达式转换为SMTlib

[英]Transform java boolean expressions to SMTlib

I have some problems trying to transform java boolean expressions to a format that Z3 is able to understand. 尝试将java布尔表达式转换为Z3能够理解的格式时,我遇到了一些问题。 I cannot use any other tool for evaluating the expressions due to some of the requirements of the project. 由于项目的某些要求,我无法使用任何其他工具来评估表达式。 Only identifiers could be used in the expressions, not functions or more complex types. 只能在表达式中使用标识符,而不能使用函数或更复杂的类型。

The possibilities I have considered are: 我考虑过的可能性是:

  • Build a parser using parboiled or a similar tool. 使用parboiled或类似工具构建解析器。 The drawback for this is that I only want to move where the operator is placed after converting it to the SMT equivalent and maybe add parentheses, so this solution and the work involving AST processing seems overworked to me. 这样做的缺点是我只想在将操作符转换为SMT等效操作符后移动操作符并可能添加括号,因此这个解决方案和涉及AST处理的工作似乎过度工作了。 Moreover, I found defining a grammar that could fit all the nested levels a bit complicated. 而且,我发现定义一个语法可以适应所有嵌套级别有点复杂。

  • Use a lexer or another kind of tool for getting the tokens and then reordering them with an algorithm similar to the Shunting-yard algorithm . 使用词法分析器或其他类型的工具来获取令牌,然后使用类似于Shunting-yard算法的算法重新排序它们。 In this case maybe the input should be required to have all the parentheses for avoiding some problems. 在这种情况下,可能需要输入所有括号以避免一些问题。

  • Use a library that could parse the expression and let it be edited. 使用可以解析表达式并让它进行编辑的库。 So far, I have not found anything but tools that let you evaluate the expression. 到目前为止,我还没有找到任何可以让你评估表达式的工具。

  • Use something that could directly transform between notations. 使用可以在符号之间直接转换的内容。 I have been searching but I was not able to find that. 我一直在寻找,但我找不到。 It would make my day, though. 不过,这将成为我的一天。

I have looked up for similar questions but I have not found anything. 我已经查找了类似的问题,但我没有找到任何东西。 I will appreciate any ideas you could have. 我会很感激您的想法。 Thanks in advance! 提前致谢!

Have you considered TXL ? 你考虑过TXL吗? TXL provides support for parsing files, applying transformations to the abstract syntax tree and printing the result. TXL支持解析文件,将转换应用于抽象语法树并打印结果。 It is easy to use, and they have a lot of documentation and a big library of grammars (Java included). 它易于使用,并且有大量文档和大型语法 (包括Java)。

You could use the free software tool bc2ncf to translate your boolean expressions to CNF (Conjunctive Normal Form) rather than to SMT. 您可以使用免费软件工具bc2ncf将您的布​​尔表达式转换为CNF (Conjunctive Normal Form)而不是SMT。 Z3 is capable to input CNF and tackle the included satisfiability problem. Z3能够输入CNF并解决所包含的可满足性问题。

The commandline syntax of Z3 tends to change now and then. Z3的命令行语法往往会改变。 Some time ago, I used something like the following: 前段时间,我使用了以下内容:

bc2cnf.exe -v test.bc.txt test.dimacs.txt

z3.exe /dimacs /v:1 test.dimacs.txt > test.solution.txt

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

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