是否可以将代码转换为逻辑图?

发布于 2024-07-25 13:52:43 字数 128 浏览 3 评论 0原文

是否可以将代码转换为逻辑图?


编辑:

我的想法是数学是绝对的。 我们可以肯定地判断它是对还是错。 但对于代码来说,除了逻辑之外还有其他东西。 我想做的就是删除那个“东西”,只保留逻辑。

Is it possible to convert code into a logical graph?


EDIT:

What I am thinking is that math is absolute. We can judge whether it is right or wrong for sure. But for code, there is something other than the logic. What I want to do is remove that 'something' to keep the logic there only.

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

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

发布评论

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

评论(5

梅倚清风 2024-08-01 13:52:43

不确定这正是您的意思,但是静态分析器(例如 clang 解析代码)会确定代码可能采用的所有可能分支,并检查错误。 例如,给定代码..

1. if(somefunction()){
2.    this_will_break();
3. } else {
4.     if(anotherfunction()){
5.         printf("%i", str(something));
6.     }
7.     print("this is fine");
8. }

您将得到如下输出:

Line 1. Taking true branch.
Line 1. Error: Function this_will_break is not defined
Line 4. Taking true branch.
Line 5. Warning: Function passed incompatible type

您可以潜在地绘制这些路径,但我不明白为什么您想要这样做(它不会真正显示任何内容)

另一个可能类似的想法是 Gprof2Dot,它获取分析数据,并绘制一个分层 Graphviz 图表,显示每个函数的持续时间需要运行,哪个函数调用它等等。

我想到的最后一件事是基于节点的应用程序,例如 ShakeQuartz Composer - “可视化编程”的方式,表示类似 Add(Blur(MyImage) 的代码), Blur(AlphaChannel)) as:

[MyImage]--->[Blur]----\/
                      [Add]
                       /\
[AlphaChannel]----------

这些不是逻辑图,但它们是可视化表示代码的方式,这可能会给你一些想法..也许..除非我完全误解了..

Not sure this is exactly what you mean, but static analysers like clang parse code, determine all possible branches the code could take, and check for errors. For example, given the code..

1. if(somefunction()){
2.    this_will_break();
3. } else {
4.     if(anotherfunction()){
5.         printf("%i", str(something));
6.     }
7.     print("this is fine");
8. }

You will get output along the lines:

Line 1. Taking true branch.
Line 1. Error: Function this_will_break is not defined
Line 4. Taking true branch.
Line 5. Warning: Function passed incompatible type

You could potentially graph these paths, but I don't see why you would want to (it wouldn't really show anything)

Another possibly similar idea is Gprof2Dot, which takes profiling data, and draws a hierarchal Graphviz chart showing how long each function takes to run, which function called it and so on.

A final thing springs to mind, which is nodal based applications like Shake, or Quartz Composer - ways of "programming visually", representing code like Add(Blur(MyImage), Blur(AlphaChannel)) as:

[MyImage]--->[Blur]----\/
                      [Add]
                       /\
[AlphaChannel]----------

Those aren't logical graphs, but they are ways of visually representing code, which might possibly give you some ideas.. maybe.. unless I'm totally misunderstanding..

咿呀咿呀哟 2024-08-01 13:52:43

这是可能的。 流程图是逻辑图,可以很容易地由计算机生成。 每个代码结构都有对应的流程图结构

快速谷歌提出:代码视觉到流程图


as far as inverse, flowcharts are much too broad to convert to code.
There are graphical programming languages though. for instance NI's labView fpga is all graphical programming which can then be converted into VHDL.

it's possible. flowcharts are logical graphs and could easily be generated by a computer. Every code structure has a corresponding flowchart structure.

quick google brought up: Code Visual to Flowchart


as far as inverse, flowcharts are much too broad to convert to code.
There are graphical programming languages though. for instance NI's labView fpga is all graphical programming which can then be converted into VHDL.

固执像三岁 2024-08-01 13:52:43

至少相反是可能的。 在对西门子 PLC 进行编程时,最常见的编程形式之一是“梯形逻辑”,即以图形方式进行编程。

http://en.wikipedia.org/wiki/Ladder_logic

At least the inverse is possible. When programming Siemen's PLCs one of the more common programming forms is "Ladder Logic", where you program graphically.

http://en.wikipedia.org/wiki/Ladder_logic

任性一次 2024-08-01 13:52:43

或者像逆向工程 UML 一样,带有类图和序列图?

在我看来,不如代码本身有价值。 一旦达到有意义的复杂程度,就不可能理解整个图表或图形。 那些可以有效地用图表表示的问题并不值得付出努力。

没有任何类型的图形表示的调试器或单元测试。

图片和设计的价值在于让你充分理解问题并进行编码。 但一旦达到这一点,我认为将它们等同于工程图纸的边际效用就不值得付出努力。

Or like reverse engineered UML, with class and sequence diagrams?

Not as valuable as the code itself, IMO. Once you reach a meaningful degree of complexity it's impossible to take in an entire diagram or graph. And the problems that can be graphed effectively aren't worth the effort.

No debuggers or unit tests for graphical representations of any kind.

The value of pictures and design is to reach a point where you understand the problem well enough to code. But once you reach that point, I'd argue that the marginal utility of making them equivalent to engineering drawings isn't worth the effort.

半步萧音过轻尘 2024-08-01 13:52:43

这只是与您想要的相反,但是 csgraph.com 允许您绘制图表并生成其代码形式调整列表或调整矩阵格式。

网页视图截图

This merely serves the inverse of what you want but csgraph.com allows you to draw graphs and generate their code form in either Adj List or Adj Matrix format.

Screenshot of Webview

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