Mar13 - CSE302: Compiler Design Instructor: Dr. Liang Cheng...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University March 13, 2007
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/13/07 Outline ± Recap ± Top-down parsing (Section 4.4) ± Summary and homework
Background image of page 2
Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/13/07 Top-Down Parsing ± Finding a leftmost derivation for an input string ± At each step the key problem is determining the production to be applied for a nonterminal, say A ± Recursive-descent parsing ± Predictive parsing for LL(1) grammars
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/13/07 Recursive-Descent Parsing ± void A() { record input pointer; Choose an A-production, A X 1 2 … X n for (i=1 to n) { if (X i is a nonterminal) call X (); else if (X equals the current input a) advance the input to the next symbol; else /* an error occurred, backtrack */ } } ± Grammar ± S cAd ± A ab| a ± Input string ± cad
Background image of page 4
Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/13/07 Predictive Parsers ± Recursive-descent parsers with one input symbol lookahead that requires no backtracking ± No backtracking means deterministic in choosing a production ± Can be constructed for a class of grammars called LL(1) ± 1 st L: scanning the input from left to right ± 2 nd L: producing a leftmost derivation
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/13/07 FIRST and FOLLOW Sets ± FIRST( α ) is the set of terminals that begin strings derived from α ± FOLLOW sets for ALL nonterminals A ± Place $ in FOLLOW(S), where S is the start symbol, and $ is the input right endmarker ± $ is not a symbol of any grammar ± If there is a production A →α B β , then everything in FIRST( β ) except ε is in FOLLOW(B) ± If there is a production A B, or a production A β , where FIRST( β ) contains ε (i.e. β⇒ ε ), then everything in FOLLOW(A) is is in FOLLOW(B) ± Whatever followed A must follow B *
Background image of page 6
Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/13/07 LL(1) Grammars ± Whenever A →α and A →β are two distinct A-productions of G, the following conditions hold ± For no terminal a do both α and β derive strings beginning with a ± At most one of α and β
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

Mar13 - CSE302: Compiler Design Instructor: Dr. Liang Cheng...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online