Grammar for language not ending on "01"

401 Views Asked by At

I want to write a grammar for a language not ending on "01". I found the regular expression here:

regular expression

I tried the following:

S-->1S11| 0S10|01S00|00|10|11|lambda

Somebody please guide me.

Zulfi.

1

There are 1 best solutions below

0
On BEST ANSWER

With the regular expression:

$\epsilon+0+1+(0+1)^*(00+10+11)$

There are four possibilities: (1) empty string; (2) $0$; (3) $1$; and (4) longer strings.

We can directly replicate this in the grammar

$S \rightarrow \epsilon|0|1|T$

$T \rightarrow 0T|1T|00|10|11$

As you can see, $S$ can directly do the first three possibilities or do the fourth possibility using $T$. $T$ builds up bigger strings by allowing any number of $0$'s and $1$'s and then ending with either $00$, $10$, or $11$ (to prevent it from ending with $01$).