Question

Given the following grammar: A -> A ; B A -> B                                   &nb

Given the following grammar:

A -> A ; B

A -> B

                                       B -> B , C

                                       B -> C

                                       C -> ( A )

                                       C -> a

rewrite the grammar to avoid left recursion

For the rewritten grammar of question , Compute First, Follow, and nullable.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The given grammar is :

A -> A ; B

A -> B

B -> B , C

B -> C

C -> ( A )

C -> a

The given grammar is converted to the following equivalent grammar without left recursion :

A -> B A '

A ' -> ; B A ' | ε

B -> C B '

B ' -> , C B ' | ε

C -> ( A )

C -> a

The First of all the variables is computed as follows :

First(A) = { ( a }

First(A') = { ; ε }

First(B) = { ( a }

First(B') = { , ε }

First(C) = { ( a }

The Follow of all the variables is computed as follows :

Follow(A) = { $  ) }

Follow(A') =   { $  ) }

Follow(B) = { ; $  ) }

Follow(B') = { ; $  ) }

Follow(C) = { , ; $  ) }

The nullable variables refer to the variables which yield ε on 0 or more steps.

The nullable variables are A ' and B ' .

Add a comment
Know the answer?
Add Answer to:
Given the following grammar: A -> A ; B A -> B                                   &nb
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT