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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 27, 2007 Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/27/07 Outline Recap Writing a grammar (Section 4.3) Top-down parsing (Section 4.4) Summary and homework Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/27/07 Writing A Grammar Eliminating ambiguity Elimination of left recursion For top-down parsing Left factoring For top-down parsing Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/27/07 Outline Recap Top-down parsing (Section 4.4) Summary and homework Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/27/07 Top-Down Parsing At each step the key problem is determining the production to be applied for a nonterminal, say A Recursive-descent parsing May require backtracking to find the correct A- production Predictive parsing No backtracking is required Look ahead at the input a fixed number (k) of symbols LL(k) class grammars Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/27/07 Recursive-Descent Parsing void A() { Choose an A-production, A X 1 X 2 X n for (i=1 to n) { if (X i is a nonterminal) call X i (); else if (X i equals the current input a) advance the input to the next symbol; else /* an error occurred, backtrack */ } } Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/27/07 Predictive Parsers Recursive-descent parsers with one input symbol lookahead that requires no backtracking No backtracking: being 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 Instructor: Dr. Liang Cheng CSE302: Compiler Design 02/27/07 FIRST Function and Set During top-down parsing, FIRST and FOLLOW allow...
View Full Document

Page1 / 22

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

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

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