仅包含 if/else 语句的程序中未读取的变量

发布于 2024-12-20 00:41:17 字数 47 浏览 3 评论 0原文

给定一个仅包含 if/else 语句的程序,是否可以决定哪些变量发生但从未读取?

Given a program with only if/else statements is it then possible to decide which variables that occur but never read?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮萍、无处依 2024-12-27 00:41:17

是的。给定一个仅包含 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]

顾挽 2024-12-27 00:41:17

您可以将跟踪或调试语句放置在特定的 if 块中,例如

if (assertion) 
{
    // print or echo or var_dump etc..
} 
else if(assertion) 
{
    // print or echo or var_dump etc..
} 
else if(assertion) 
{
    // print or echo or var_dump etc..
}

如果您可以通过这种方式跟踪代码,则可以断言块内的任何变量或代码都将被执行/读取。

You could place trace, or debugging statements in the specific if blocks, like

if (assertion) 
{
    // print or echo or var_dump etc..
} 
else if(assertion) 
{
    // print or echo or var_dump etc..
} 
else if(assertion) 
{
    // print or echo or var_dump etc..
}

If you can trace the code this way, you can assert any variable or code within the block would be executed/read.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文