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

Info iconThis preview shows pages 1–6. 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
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 March 22, 2007 Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/22/07 Outline Recap LR(0) parsing and SLR(1) parsing General/Canonical LR(1) parsing Lookahead LR(1) / LALR(1) parsing Summary and homework Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/22/07 The LR(0) and SLR(1) Parsing Algorithms LR( ) parsing If state s contains A .X where X is a terminal, then shift and the state changes to s containing A X. If state s contains A ., then reduce by A ( stack ops ) and the state changes to s containing B A. SLR(1) parsing If state s contains A .X where X is a terminal, and the lookahead token is X , then shift and the state changes to s containing A X. If state s contains A ., and the lookahead token is in FOLLOW(A) , then reduce by A ( stack ops ) and the state changes to s containing B A. Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/22/07 Another Example Another example stmt call-stmt | assign-stmt call-stmt identifier assign-stmt var=expr var identifier expr var | number Is this an SLR(1) grammar? Instructor: Dr. Liang Cheng CSE302: Compiler Design 03/22/07 Observations SLR(1) parsing is more powerful than LR(0) parsing due to its consideration of lookaheads in the...
View Full Document

Page1 / 15

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

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

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