Successfully reported this slideshow.
Your SlideShare is downloading. ×

shift and reduce.ppt

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
ch7.ppt
ch7.ppt
Loading in …3
×

Check these out next

1 of 2 Ad

More Related Content

Recently uploaded (20)

Advertisement

shift and reduce.ppt

  1. 1. 1 Bottom-up parsing  Goal of parser : build a derivation  Top-down parser : build a derivation by working from the start symbol towards the input.  Builds parse tree from root to leaves  Builds leftmost derivation  Bottom-up parser : build a derivation by working from the input back toward the start symbol  Builds parse tree from leaves to root  Builds reverse rightmost derivation
  2. 2. 2 Example: Shift-reduce parsing 1. S  E 2. E  E + E 3. E  E * E 4. E  num 5. E  id Input to parse: id1 + num * id2 Accept $ S Reduce (rule 1) $ E Reduce (rule 2) $ E + E Reduce (rule 3) $ E + E * E Reduce (rule 5) $ E + E * id2 Shift $ E + E * Shift $ E + E Reduce (rule 4) $ E + num Shift $ E + Shift $ E Reduce (rule 5) $ id1 Shift $ ACTION Grammar: Handles: underlined STACK

×