Question: Show a complete parse, including the parse stack contents, input string, and action for the string (id + id) * id, using the grammar and

Show a complete parse, including the parse stack contents, input string, and action for the string (id + id) * id, using the grammar and parse table in Section 4.5.3.


Table in Section 4.5.3.

Consider the traditional grammar for arithmetic expressions that follows:

1. E→E+T

2. E→T
3. T→T*F

4. T→F

5. F→(E)

6. F→id

Figure 4.5 parse table

State id S5 S5 10 Action S6 R4 R44 R6 R6 S6 R3 R3 S4 S4 S4 S4 accept R2 R2 R4 R4 R6 R6 S11 R1 R1 R3 R3 RS RS Goto E T F 10


Following is a trace of a parse of the string id + id, using the LR parsing algorithm and the parsing table shown in Figure 4.5.

Stack Input Action Shift 5 Reduce 6 (use GOTO|0, F) Reduce 4

Stack Input Action Shift 5 Reduce 6 (use GOTO|0, F) Reduce 4 (use GOTO[0, T]) Reduce 2 (use GOTOJ0, El) Shift 6 Shift 5 Reduce 6 (use GOTO[6, F) Reduce 4 (use GOTO(6, T]) Shift 7 Shift 5 Reduce 6 (use GOTO[7, F) Reduce 3 (use GOTO[6, T]) Reduce 1 (use GOTO[0, El) Accept id + id * id S Oid5 OF3 OT2 + id * id $ SP!. P! + + id * id $ OEI OE1+6 S P!. P! + OE1+6ids OE1+6F3 id * id S * id S *id S SP!. id $ OE1+6T9 OE1+6T9*7 $ OE1+6T9*7id5 OE1+6T9*7F10 OE1+6T9 OE1

Step by Step Solution

3.51 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Given Grammar below E ET E ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Concepts Of Programming Languages 10th Questions!