English 中文(简体)
固定控制流量图以结构化代码
原标题:Flattening a control flow graph to structured code

我要把控制流图(CFG)放到高级别法典。 通常,这非常容易;走树,使每一根基都翻一番,与山.一.。

不幸的是,这些日子已经过时,大多数现代语言不支持这些语言。 因此,我需要一些办法,只使用现有语文的控制流表:for,while,do.while,if ,break and continue 。 (不愿考虑使用变量建造国家机器。)

看来,虽然有计算法,但每例工作将而不是<>em>。 也就是说,可能建立一个仅使用上述有限控制流动结构的、不能归结为结构化代码的CFG。

This seems intuitively obvious to me, but I can t prove it (and the documentation for the algorithms I ve found don t go into more detail). And I haven t been able to find an example of a CFG which can t be flattened like this.

I would like to know, definitively, if this is possible or not.

备选办法(a):任何人都有一个无法如上所述加以统一的儿童援助基金的例子吗? (Which将告诉我,这是不可能的。)

备选办法(b):是否有任何证据表明,如上所述,CFGs can被统一起来? (Which将告诉我,它is可能)。 这样做的算法也是非常可取的,因为届时我不得不这样做......

最佳回答

我认为我取得了成果。

The answer seems to be: it is not possible. This is from Communications of the ACM, volume 9, pages 366 to 371 in a paper from 1966 called "Flow Diagrams, Turing Machines and Languages with only Two Formation Rules" by Giuseppe Jacopini. CiteSeer link. (Which, amusingly, I found referenced from Knuth s seminal (and, from my point of view, incredibly annoying) Go To Statement Considered Harmful.)

他们没有证据,说他们找不到证据。

好消息是,该文件确实描述了一种战略,即利用有限的控制流动机制,尽可能少地利用国家,将任意的CFG转化为CFG。 该文件相当艰难,但看起来很有希望。

问题回答

“irreducible

上述图表虽然是不可估量的,但随着添加“jump”等助变,可以有条理地进行控制。 我们添加了比x的一块块块,它 sets起 jump,然后飞到x。 然后,我们制造了一个新编块, sets起休战,把右边从X射出,而不是z。 然后,我们直接诉X, 和 z ,进入一个新的区块,条件是跳跃, z 否则。 之后,z公司的第一份陈述补充了跳跃=虚假。 这就增加了最低限度的法典,没有重复,并将这一结构变成一个单一条目。

减少不可减少的控制流动:

“reducing





相关问题
Is transactions over machine boundary (via tcp-ip) possible?

Theoretically, can one define a protocol where one machine does some remote calls on another machine (or more than one), and where in any part of the process, if any of the machines (or operations) ...

How to write an enumeration of all computable functions?

Motivation: I d like to be able to use toy functional programming in languages without first-order functions, by using natural numbers instead of functions. A universal function is a function f : N ->...

Best-case Running-time to solve an NP-Complete problem?

What is the fastest algorithm that exists up with to solve a particular NP-Complete problem? For example, a naive implementation of travelling salesman is O(n!), but with dynamic programming it can be ...