简体   繁体   中英

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.

The picture below shows the process of expressing the expression as NFA and then converting it to DFA. 在此处输入图像描述

在此处输入图像描述

So if you get regular grammar from DFA,

A-> aB | bC | e

B-> aB | bA | e

C-> aC | bC

But the problem is, when you get the regular expression with this grammar, you get a much more complex expression, not (a+b)*.

C = aC + bC = (a+b)*

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)

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)*. Here I tried to explain my steps for simplifying X to (a+b)*:

  1. We will divide our simplification into three parts: 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)*.
  2. If you take the first part (aa*b)* as e and look at the second part, you will see that we can obtain a) empty string and b) every possible string starting with b . We only need to obtain c) every possible string starting with a .
  3. This part was a struggle but I think I obtained it. Now we look only for strings starting with a. First of all, we have aa* in the second part obtaining all 'a's. Moreover, if we have 2 or more consecutive 'b's, the rest of the string will be accepted by the second part b(a+b)*. So the only concern is single 'b's. Finally, single 'b's are obtained by the first part.

Although it was complicated (and probably unnecessary), this is a proof that X=(a+b)*. As a result, your solution was correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM