{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L6-Parsing1 - Introduction to Compiler Design Syntax...

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

View Full Document Right Arrow Icon
Introduction to Compiler Design Syntax Analysis: Top-Down and Bottom-Up Parsing Professor Yi-Ping You Department of Computer Science http://www.cs.nctu.edu.tw/~ypyou/ Page 1 Introduction to Compiler Design, Spring 2010
Image of page 1

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

View Full Document Right Arrow Icon
Recall: Overview of Syntax Analysis Goal – determine if the input token stream satisfies the syntax of the program What do we need to do this? An expressive way to describe the syntax A mechanism that determines if the input token stream satisfies the syntax description Context-free Parser Context free grammar, G Token stream s Yes, if s in L(G) No, otherwise Token stream, s (from scanner) Error messages Page 2 Introduction to Compiler Design, Spring 2010
Image of page 2
RE/Scanner RE/Scanner v.s v.s. Grammar/Parser . Grammar/Parser Lexical analysis We use regular expressions to specify the lexical definitions of programming languages Given a character stream, a scanner outputs a token stream upon the lexical definitions Syntax analysis We use context-free grammars to specify the grammatical structure of programming languages Given a token stream a parser outputs a syntax tree Given a token stream, a (parse tree) upon the grammatical definitions Page 3 Introduction to Compiler Design, Spring 2010
Image of page 3

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

View Full Document Right Arrow Icon
Outline Top-Down Parsing Recursive Descent Parsing Recursive-Descent Parsing Predictive Parsing (LL(k) Parsing) N i P di i P i Nonrecursive Predictive Parsing Error Recovery Bottom-Up Parsing Shift Reduce Parsing Shift-Reduce Parsing LR(0) Parsing Si l LR (SLR) P i Simple LR (SLR) Parsing Page 4 Introduction to Compiler Design, Spring 2010
Image of page 4