patternMinor
Context-free language and regular expressions
Viewed 0 times
freeandregularexpressionslanguagecontext
Problem
I have the following context-free language:
I don't understand why this is not regular. I first said that it's generated by the regular expression
e stands for the empty string. I don't understand their differences.
S -> ASa | b
A -> aA | aI don't understand why this is not regular. I first said that it's generated by the regular expression
a+ba+. The following is regular howeverS -> ASa | b
A -> aA | ee stands for the empty string. I don't understand their differences.
Solution
The subtlety is that in the first case, the number of $a$'s before the unique $b$ must be at least the number of $a$ after, i.e. your language is $\{a^nba^m|n\geq m\}$, so it is not regular. This is because each $A$ produces at least one $a$.
In the second case however, this constraint disappears, and your language becomes indeed $b+a^*ba^+$ which is regular.
In the second case however, this constraint disappears, and your language becomes indeed $b+a^*ba^+$ which is regular.
Context
StackExchange Computer Science Q#21629, answer score: 7
Revisions (0)
No revisions yet.