Regular Grammar

369 Views Asked by At

Devise a regular grammar in normal form that generates the language L.
Let L be the language consisting of all binary numbers divisible by 4. I know the different aspects needed to be generated:
starting point, non terminals and production rules etc. Need help on how to generate though

1

There are 1 best solutions below

0
On BEST ANSWER

A binary string is divisible by 4 if and only if it is $0$ or ends in $00$.

So, you could pretty easily do something like $$ \begin{align*} S&\rightarrow0\\ S&\rightarrow 1N\\ N&\rightarrow 0N\\ N&\rightarrow 0F\\ F&\rightarrow0 \end{align*} $$ Explanation:

Our underlying alphabet (set of terminals) is $\{0,1\}$. $S$ is our start, $N$ is a non-terminal representing the part of any such non-zero number that follows the initial $1$, and $F$ is a non-terminal indicating that we've put in the first of our two final $0$'s.

From $S$ you either go straight to $0$ and are done, or you have an initial $1$. Following an initial $1$ is any number of $0$'s and $1$'s, followed by a final $00$.