Reputation: 1
I am having trouble coming up with a left-linear and right-linear grammar for the following regular expression.
0(0+1)*+10^+
I am also quite confused on what the plus-closure does.
This is what I got for the left linear grammar, but I am not sure if this is correct:
P: S--> 0A | 1A
A--> A0|A1|0S|0| epsilon
Thank you!
Upvotes: 0
Views: 1651
Reputation: 372684
One general good way to find left- and right-linear grammars is to find an NFA that has the same language as your regex, then convert that NFA into a left- or right-linear grammar using the following mechanical transform:
Then, for left-linear grammars:
Then, for right-linear grammars:
Try applying this idea here and you'll end up producing left- and right-linear grammars for your language. They might not be the most efficient grammars, but they'll work.
Upvotes: 2