【发布时间】:2016-02-28 14:09:16
【问题描述】:
以下伪代码来自Java World 中的编译器构造简介一书。该算法应该输出非确定性有限机器的一组状态的 epsilon 闭包(最终将其转换为确定性机器)。
# Input: a set of states, S
# Output: epsilon_closure(S)
Stack P.addAll(S) #a stack containing all states in S
Set C.addAll(S) #the closure initially contains the states in S
while ! P.empty() do
s = P.pop()
for r in m(s, epsilon) do
# m(s, epsilon) is a set of states
if r not in C then
P.push(r)
C.add(r)
end if
end for
end while
return C
我知道什么是 epsilon 闭包,但不幸的是我很难理解这段代码是如何工作的。
注意:代码中的m()是机器的转换函数。
【问题讨论】:
标签: algorithm pseudocode finite-automata dfa nfa