{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec11mod

# lec11mod - CS415 Compilers LL(1 parsing table driven and...

This preview shows pages 1–6. Sign up to view the full content.

CS415 Compilers LL(1) parsing, table driven and recursive descent parser These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

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

View Full Document
Lecture 11 2 cs415, spring 10 Review - Predictive Parsing Basic idea Given A α | β , the parser should be able to choose between α & β F IRST sets For some rhs α G , define F IRST ( α ) as the set of tokens that appear as the first symbol in some string that derives from α That is, a F IRST ( α ) iff α * a γ , for some γ The LL(1) Property If A → α and A → β both appear in the grammar, we would like F IRST ( α ) F IRST ( β ) = This would allow the parser to make a correct choice with a lookahead of exactly one symbol ! This is almost correct, but not quite
Lecture 11 3 cs415, spring 10 The FOLLOW Set For a non-terminal A, define FOLLOW(A) as FOLLOW(A) := the set of terminals that can appear immediately to the right of A in some sentential form. Thus, a non-terminal’s FOLLOW set specifies the tokens that can legally appear after it; a terminal has no FOLLOW set

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

View Full Document
Lecture 11 4 cs415, spring 10 Predictive Parsing If A → α and A → β and ε F IRST ( α ), then we need to ensure that F IRST ( β ) is disjoint from F OLLOW (A), too Define F IRST + ( δ ) for rule A δ as (F IRST ( δ ) – { ε }) F OLLOW ( A ), if ε F IRST ( δ ) F IRST ( δ ), otherwise
Lecture 11 5 cs415, spring 10 The LL(1) Property A grammar is LL(1) iff A → α and A → β implies F IRST + ( α ) F IRST + ( β ) = This would allow the parser to make a correct choice with a lookahead of exactly one symbol ! Question : Can there be two rules A → α and A → β in a LL(1) grammar such that ε F IRST( α ) and ε F IRST( β )?

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.