I have following regular expression: ((abc)+d)|(ef*g?)
I have created a DFA (I hope it is correct) which you can see here
The task is to create a regular grammar (Chomsky hierarchy Type 3) and I don't get it. But I created a regular grammar, which looks like this:
S → aT
T → b
T → c
T → dS
S → eT
S → eS
T → ε
T → f
T → fS
T → gS
Best Regards Patrick
Type 3 Chomsky are the class of regular grammars constricted to the use of following rules:
in which X is an arbitrary non-terminal and a an arbitrary terminal. The rule
A -> eps
is only allowed ifA
is not present in any of the right hand sides.Construction
We notice the regular expression consists of two possibilities, either (abc)+d or ef*g?, our first rules will therefor be
S -> aT
andS -> eP
. These rules allow us to start creating one of the two possibilities. Note that the non-terminals are necessarily different, these are completely different disjunct paths in the corresponding automaton. Next we continue with both regexes separately:(abc)+ We have at least one sequence abc followed by 0 or more occurrences, it's not hard to see we can model this like this:
ef*g? Here we have an e followed by zero or more f characters and an optional g, since we already have the first character (one of the first two rules gave us that), we continue like this:
Conclusion
Put these together and they will form a grammar for the language. I tried to write down the train of thought so you could understand it.
As an exercise, try this regex: (a+b*)?bc(a|b|c)*