lec09mod - CS415 Compilers Syntax Analysis CFG,...

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

View Full Document Right Arrow Icon
CS415 Compilers Syntax Analysis CFG, derivations, ambiguity, introduction to parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture 9 2 cs415, spring 10 Parsing (Syntax Analysis) EAC Chapters 3.1 - 3.2
Background image of page 2
Lecture 9 3 cs415, spring 10 Review: The Front End Parser Checks the stream of words and their parts of speech (produced by the scanner) for grammatical correctness Determines if the input is syntactically well formed Guides checking at deeper levels than syntax Builds an IR representation of the code Source code Scanner IR Parser Errors tokens
Background image of page 3

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

View Full DocumentRight Arrow Icon
Lecture 9 4 cs415, spring 10 The Study of Parsing The process of discovering a derivation for some sentence Need a mathematical model of syntax — a grammar G Need an algorithm for testing membership in L(G) Need to keep in mind that our goal is building parsers, not studying the mathematics of arbitrary languages Roadmap 1 Context-free grammars and derivations 2 Top-down parsing LL(1) parsers, hand-coded recursive descent parsers 3 Bottom-up parsing Automatically generated LR(1) parsers
Background image of page 4
Lecture 9 5 cs415, spring 10 Specifying Syntax with a Grammar Context-free syntax is specified with a context-free grammar SheepNoise SheepNoisebaa | baa This CFG defines the set of noises sheep normally make It is written in a variant of Backus–Naur form Formally, a grammar is a four tuple, G = (S,N,T,P) Sis the start symbol (set of strings in L(G)) Nis a set of non-terminal symbols (syntactic variables) Tis a set of terminal symbols (words) Pis a set of productionsor rewrite rules (P : N ( T) + )
Background image of page 5

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

View Full DocumentRight Arrow Icon
Lecture 9 6 cs415, spring 10 Deriving Syntax We can use the SheepNoise grammar to create sentences use the productions as rewriting rules Rule Sentential Form SheepNoise 2b a a 1 SheepNoise baa a a b a a 1 SheepNoise baa 1 SheepNoise baa baa a a b a a baa And so on ...
Background image of page 6
Lecture 9 7 cs415, spring 10 A More Useful Grammar To explore the uses of CFG s,we need a more complex grammar Such a sequence of rewrites is called a derivation Process of discovering a derivation is called parsing We denote this derivation: Expr * id –num * id 1 Expr Op Expr 2 number 3 id 4 Op + 5 6 * 7 / Rule Sentential Form Expr 1 Expr Op Expr 3 < id, x > Op Expr 5 < id, x > 1 < id, x > 2 < id, x > < num, 2 > 6 < id, x > < num, 2 > * 3 < id, x > < num, 2 > * < id, y >
Background image of page 7

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

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

This note was uploaded on 10/29/2010 for the course CS 198:415 taught by Professor Kremer,u. during the Spring '10 term at Rutgers.

Page1 / 23

lec09mod - CS415 Compilers Syntax Analysis CFG,...

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

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