[英]DFA to regular expression
I have already read a couple soultions and tutorials, expecially on Stackoverflow, but can't help myself with a specific issue. 我已经阅读了一些关于灵魂的技巧和教程,尤其是关于Stackoverflow的教程,但是在解决特定问题上无济于事。 To begin with, I have this DFA:
首先,我有以下DFA:
And could reduce it to this: 并可以将其简化为:
So that I have the regular expression at (aa|ba|cc)c but missing the returning d. 这样我在(aa | ba | cc)c处有正则表达式,但是缺少返回的d。 Checking it that far with http://hackingoff.com/compilers/regular-expression-to-nfa-dfa it looks exactly like my starting DFA but without the d.
使用http://hackingoff.com/compilers/regular-expression-to-nfa-dfa进行了如此广泛的检查,它看起来就像我的起始DFA,但没有d。 I tried a lot but am very unsure how to write the d into the RE.
我做了很多尝试,但是非常不确定如何将d写入RE。
Your proposed sequence isn't quite correct, as pointed out by revo . 正如revo指出的那样,您建议的顺序不太正确。 The correct sequence is
(aa|ba|c)c
. 正确的序列是
(aa|ba|c)c
。
The regex version (in programming languages) of the whole DFA would be 整个DFA的正则表达式版本(以编程语言显示)为
/^(?:aa|ba|c)c(?:d(?:aa|ba|c)c)*$/
The formal regex would be 正式的正则表达式为
(aa|ba|c)c(d(aa|ba|c)c)*
(?:aa|ba|cc)c
is the first sequence that you already figured out (everything from q0
to q6
, without the d
path from q6
back to q0
). (?:aa|ba|cc)c
是您已经弄清楚的第一个序列(从q0
到q6
所有内容,而没有从q6
返回q0
的d
路径)。
Once a d
appears, you basically need the above sequence again . 出现
d
,基本上您将再次需要上述序列。 That second instance of the sequence including the d
can be repeated any number of times, so you use the *
quantifier. 包含
d
的序列的第二个实例可以重复任意次,因此您可以使用*
量词。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.