This preview shows pages 1–11. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSE 450: Compilers K. Stirewalt Parsing and syntax analysis Part 2: Parsing methods Topics: Topdown 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 Warmup exercises What is a context free grammar? What is a derivation? What is parsing? What is the difference between topdown and bottomup 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 Topdown 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 nonterminal 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 (topdown) parse Grammar String G = S E E E Op E E Int w = 2  1 + 1 CSE 450: Compilers K. Stirewalt Example (topdown) 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 (topdown) 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 (topdown) 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
 Spring '08
 STIREWALT

Click to edit the document details