仅包含 if/else 语句的程序中未读取的变量
给定一个仅包含 if/else 语句的程序,是否可以决定哪些变量发生但从未读取?
Given a program with only if/else statements is it then possible to decide which variables that occur but never read?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。给定一个仅包含 if/else 语句的程序 [假设没有向后分支和循环],程序中的路径数量是有限的。
你可以检查所有这些,检查必须满足哪些条件才能到达每条路径,并找到矛盾[不可访问的路径],并通过这种方式找到哪些变量从未被使用过。
这可以作为 Hoare 逻辑 的更简单版本来实现,它非常容易实现自动化,无需循环。 [对于循环,当然不可能使其自动化]
Yes. Given a program with only if/else statements [assuming no branches backwards and loops], there is a finite number of paths in the program.
You can check all of them, check which conditions must be met in order to get to each path, and find contradictions [un accessable paths], and this way to find which variables are never used.
This can be implemented as a simpler version of Hoare logic, which is pretty simple to automatize, without loops. [with loops it is of course impossible to automatize it]
您可以将跟踪或调试语句放置在特定的 if 块中,例如
如果您可以通过这种方式跟踪代码,则可以断言块内的任何变量或代码都将被执行/读取。
You could place trace, or debugging statements in the specific if blocks, like
If you can trace the code this way, you can assert any variable or code within the block would be executed/read.