Question

2. Consider the following context free grammar with terminals (), +, id, num, and starting symbol S. S (ST) F-id Fnum a. Compute the first and follow set of all non-terminals (use recursion or iteration, show all the steps) Show step-by-step (the parsing tree) how the following program is parsed: (num+num+id)) b.

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

ANSWER :

S -> F

S -> (ST)

T -> ?

T -> +FT

F -> id

F -> num

a)

FIRST function :

FIRST(S) = FIRST(F)

FIRST(S) = {(}

FIRST(T) = {?}

FIRST(T) = {?,+}

FIRST(F) = {id,num}

FIRST(S) = {(,id,num}

FOLLOW function :

FOLLOW(S) = {$,FIRST(T)} = {$,+, FIRST())} = {$,+,)}

FOLLOW(T) = {)}

FOLLOW(F) = {FOLLOW(S)} = {$,+,)}

FOLLOW(F) = {$,+,),FIRST(T)} = {$,+,),FOLLOW(T)} = {$,+,)}

FOLLOW(F) = {$,+,)}

Table for first and follow function :

FIRST

FOLLOW

S

{(,id,num}

{$,+,)}

T

{?,+}

{)}

F

{id,num}

{$,+,)}

b)

Parse Table :

(

)

+

id

num

$

S

S->(ST)

S->F

S->F

T

T->?

T->+FT

F

F->id

F->num

We have given a program ((num+num+id))

Parse Tree :

hun

Add a comment
Know the answer?
Add Answer to:
2. Consider the following context free grammar with terminals (), +, id, num, and starting symbol...
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
ADVERTISEMENT