[英]How to convert regular expressions to grammar and DFA
Hi I am trying to figure out the regular grammar that represents the regular expression L = (a+ab)* as DFA and generates L.嗨,我正在尝试找出将正则表达式 L = (a+ab)* 表示为 DFA 并生成 L 的正则语法。
The picture below shows the process of expressing the expression as NFA and then converting it to DFA.下图展示了将表达式表达为NFA,然后再转换为DFA的过程。
So if you get regular grammar from DFA,因此,如果您从 DFA 获得常规语法,
A-> aB | A-> aB | bC |
BC | e
e
B-> aB | B-> aB | bA |
巴| e
e
C-> aC | C-> 交流电 | bC
公元前
But the problem is, when you get the regular expression with this grammar, you get a much more complex expression, not (a+b)*.但问题是,当你用这个语法得到正则表达式时,你会得到一个更复杂的表达式,而不是 (a+b)*。
C = aC + bC = (a+b)* C = aC + bC = (a+b)*
B = aB + bA + e = a*(bA+e) B = aB + bA + e = a*(bA+e)
A = aB + bC + e = aa* bA + aa* + b(a+b) + e = (aa* b)* (aa* +b(a+b)*+e) A = aB + bC + e = aa* bA + aa* + b(a+b) + e = (aa* b)* (aa* +b(a+b)*+e)
I wonder if there is a problem with my solution.我想知道我的解决方案是否有问题。
Actually X = (aa*b)*(aa*+b(a+b)*+e) can be simplified to (a+b)*.实际上 X = (aa*b)*(aa*+b(a+b)*+e) 可以简化为 (a+b)*。 Here I tried to explain my steps for simplifying X to (a+b)*:
在这里,我试图解释我将 X 简化为 (a+b)* 的步骤:
a) empty string
, b) every possible string starting with b
, c) every possible string starting with a
.a) empty string
, b) every possible string starting with b
, c) every possible string starting with a
。 If we can obtain these, it will mean that X=(a+b)*.a) empty string
and b) every possible string starting with b
.a) empty string
和b) every possible string starting with b
。 We only need to obtain c) every possible string starting with a
.c) every possible string starting with a
。 Although it was complicated (and probably unnecessary), this is a proof that X=(a+b)*.尽管它很复杂(并且可能没有必要),但这是 X=(a+b)* 的证明。 As a result, your solution was correct.
结果,您的解决方案是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.