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

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

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

View Full Document
Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/13/07 Outline ± Recap ± Top-down parsing (Section 4.4) ± Summary and homework
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

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

View Full Document
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
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

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

View Full Document
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 *
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 β

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}