0
$\begingroup$

This is my first attempt at converting a context free grammar into chomsky normal form. I think I have the correct answer, would just appreciate any feedback if I have gone wrong somewhere.

Context Free Grammar

V = {M, N, O}

Σ = {+, *, (, ), x}

R = {

M ---> M + N

M ---> N

N ---> O * N

N ---> O 

O ---> ( M )

O ---> x

Chomsky Normal Form Conversion

Step One

M appears on the right hand side, so I create a new state called A:

A ---> M

M ---> M + N

M ---> N

N ---> O * N

N ---> O 

O ---> ( M )

O ---> x

Step Two

Ignored, as there are no epsilon symbols

Step Three

Give terminals next to non-terminals their own rule:

A ---> M Y N

M ---> M Y N

M ---> O Z N

N ---> O Z N

N ---> Q M P

O ---> Q M P

O ---> x

Y ---> +

Z ---> *

Q ---> (

P ---> )

Step Four

Remove unit productions

A ---> B N

M ---> B N

M ---> C N

N ---> C N

N ---> D P

O ---> D P

O ---> x

Y ---> +

Z ---> *

Q ---> (

P ---> )

B ---> M Y 

C ---> O Z

D ---> Q M

So Final Context Free Grammar is...

A ---> B N

M ---> B N

M ---> C N

N ---> C N

N ---> D P

O ---> D P

O ---> x

Y ---> +

Z ---> *

Q ---> (

P ---> )

B ---> M Y 

C ---> O Z

D ---> Q M
$\endgroup$
  • 1
    $\begingroup$ We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. This site works better for asking about a specific conceptual issue you're uncertain about. As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. $\endgroup$ – D.W. Nov 8 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.