Question

Given the following grammar and LR Parser table, trace the parse of “id+id*id” and draw the...

  1. Given the following grammar and LR Parser table, trace the parse of “id+id*id” and draw the parse tree.

(1) E -> E + T

(2) E -> E – T

(3) E -> T

(4) T -> T * F

(5) T -> T / F

(6) T -> F

(7) F -> (E)

(8) F -> id

State

id

+

-

*

/

(

)

$

E

T

F

0

S5

S4

1

2

3

1

S6

S7

Acc

2

R3

R3

S8

S9

R3

R3

3

R6

R6

R6

R6

R6

R6

4

S5

S4

10

2

3

5

R8

R8

R8

R8

R8

R8

6

S5

S4

11

3

7

S5

S4

12

3

8

S5

S4

13

9

S5

S4

14

10

S6

S7

S15

11

R1

R1

S8

S9

R1

R1

12

R2

R2

S8

S9

R2

R2

13

R4

R4

R4

R4

R4

R4

14

R5

R5

R5

R5

R5

R5

15

R7

R7

R7

R7

R7

R7

Stack                                                   Input                Entry               Action/Production

_____________________________________________________________________

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

The trace for the string id + id * id is :

Stack Input Entry Actions
$ id+id*id $ Shift id
$id +id*id $ Reduce F -> id
$F +id*id $ Reduce T -> F
$T +id*id $ Reduce E -> T
$E +id*id $ Shift +
$E+ id*id $ Shift id
$E+id *id $ Reduce F -> id
$E+F *id $ Reduce T -> F
$E+T *id $ Shift *
$E+T * id $ Shift id
$E+T*id    $ Reduce F -> id
$E+T*F $ Reduce T -> T*F
$E+T $ Reduce E -> E+T
$E $ accept

The parse tree for the string is :

Add a comment
Know the answer?
Add Answer to:
Given the following grammar and LR Parser table, trace the parse of “id+id*id” and draw the...
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