02-02parsingMethods - CSE 450 Compilers K Stirewalt Parsing...

Info iconThis preview shows pages 1–11. 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

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: CSE 450: Compilers K. Stirewalt Parsing and syntax analysis Part 2: Parsing methods Topics: – Top-down parsing methods – Recursive descent parsing – Sensitivity of parsing method to “shape” of grammar – Grammar transformations – Parse trees and problem of ambiguity CSE 450: Compilers K. Stirewalt Warm-up exercises What is a context free grammar? What is a derivation? What is parsing? What is the difference between top-down and bottom-up parsing? CSE 450: Compilers K. Stirewalt For today... I want to introduce the rich design space of different parsing methods, starting with the simplest to implement While each method is quite different, and some involve complex algorithms, we can understand all of them in terms of the notion of derivations We can find derivations by hand pretty easily Parsing algorithms merely systematize and impose some order in resolving choices so as to produce certain classes of derivations CSE 450: Compilers K. Stirewalt Parsing Several ways to think about it: 1. Process of demonstrating a string, say w , is in L(G) for some grammar G 2. Process of producing (or elaborating) a parse tree that demonstrates w ∈ L(G) 3. Process of producing a derivation of w from the start symbol S of grammar G Parsing approaches/algorithms based mostly on the third notion CSE 450: Compilers K. Stirewalt Top-down parsing (theory) Given a context free grammar G with start symbol S and a string of tokens w Produces derivation S ⇒ γ 1 ⇒ γ 2 ⇒ … ⇒ γ n = w – start with sentential containing only S – rewrite sentential γ k into new sentential γ k+1 by: • choosing some non-terminal symbol A at position x in γ k • choosing a rule of the form A → β • replacing A with β at position x in γ k – Eventually yielding w , if w ∈ L(G) CSE 450: Compilers K. Stirewalt Example (top-down) parse Grammar String G = S → E E → E Op E E → Int w = 2 - 1 + 1 CSE 450: Compilers K. Stirewalt Example (top-down) parse Grammar Tokenized String G = S → E E → E Op E E → Int w = 2 - 1 + 1 = Int Op Int Op Int CSE 450: Compilers K. Stirewalt Example (top-down) parse Grammar String Derivation (begins with S) G = S → E E → E Op E E → Int w = 2 - 1 + 1 = Int Op Int Op Int S CSE 450: Compilers K. Stirewalt Example (top-down) parse Grammar String Derivation Select symbol… G = S → E E → E Op E E → Int w = 2 - 1 + 1 = Int Op Int Op Int S CSE 450: Compilers K. StirewaltK....
View Full Document

This note was uploaded on 07/25/2008 for the course CSE 450 taught by Professor Stirewalt during the Spring '08 term at Michigan State University.

Page1 / 38

02-02parsingMethods - CSE 450 Compilers K Stirewalt Parsing...

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

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