I am confused with this CFG. I want to convert it into a regular expression:
A -> aA | B | epsilon
B -> bB | A
Please also mention the conversion rule from CFG to RE.
I am confused with this CFG. I want to convert it into a regular expression:
A -> aA | B | epsilon
B -> bB | A
Please also mention the conversion rule from CFG to RE.
I suppose you're talking about formal regular expression here.
Short answer: this is simply:
(a | b)*
.Why? Let's see:
This is equivalent to this grammar:
See something here?
These are equivalent. Let's just replace
B
withA
:Reorder this:
Rewrite it with ORs
Factor it:
Simplify:
Which is:
Or, in concrete PCRE notation:
[ab]*
.Also, it's not clear from your question, but you should be aware that only some CFGs can be translated to regular expressions.