Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shift-Reduce Parsing Example 1

Similar presentations


Presentation on theme: "Shift-Reduce Parsing Example 1"— Presentation transcript:

1 Shift-Reduce Parsing Example 1
Mr. Lupoli F2012

2 Mechanics Goal Shift Reduce
trace that the given input can be reduced BACK to the original start symbol Shift marker that moves along the input from left to right what is on left needs to be reduced match with production table Reduce apply the inverse production

3 What’s Given E → int E  E + (E) Original Production
Syntax to be checked int + (int) + (int)

4 E → int E  E + (E) | int + (int) + (int)

5 E → int E  E + (E) int | + ( int ) + ( int ) E | + ( int ) + ( int )
we have a match!! Reduce E | + ( int ) + ( int )

6 E → int E  E + (E) E + | ( int ) + ( int ) no match shift 

7 E → int E  E + (E) E + ( | int ) + ( int ) no match shift 

8 E → int E  E + (E) E + ( int | ) + ( int ) E + ( E | ) + ( int )
match !!! Reduce E + ( E | ) + ( int )

9 E → int E  E + (E) E + ( E ) | + ( int ) match!! Reduce E | + ( int )

10 E → int E  E + (E) E + | ( int ) no match, shift 

11 E → int E  E + (E) E + ( | int ) no match, shift 

12 E → int E  E + (E) E + ( int | ) found a match!! Reduce!! E + ( E | )

13 E → int E  E + (E) E + ( E ) | found a match!! Reduce!! E

14 E → int E  E + (E) E starting production!!! ACCEPT!!!

15 In total  int + (int) + (int)$ shift
int  + (int) + (int)$ red. E  int E  + (int) + (int)$ shift 3 times E + (int  ) + (int)$ red. E  int E + (E  ) + (int)$ shift E + (E)  + (int)$ red. E  E + (E) E  + (int)$ shift 3 times E + (int  )$ red. E  int E + (E  )$ shift E + (E)  $ red. E  E + (E) E  $ accept

16 Sources CS 671 – University of Virginia


Download ppt "Shift-Reduce Parsing Example 1"

Similar presentations


Ads by Google