160 likes | 306 Views
Top-Down parsing. LL(1) parsing. Overview of Top-Down. There are only two actions Replace Match. Overview of Top-Down. e.g. with grammar. LL(k) parsing. L stands for left-to-right parse of input L stands for leftmost-derivation k stands for k-token look-ahead. LL(1) Parsing.
E N D
Top-Down parsing LL(1) parsing
Overview of Top-Down • There are only two actions • Replace • Match
Overview of Top-Down • e.g. with grammar
LL(k) parsing • L stands for left-to-right parse of input • L stands for leftmost-derivation • k stands for k-token look-ahead
LL(1) Parsing • At top of Parsing stack • For Non-terminal • Replace: a decision must be made, based on the current input token. • For terminal • Match: no decision is to be made but need to see if it is the same as the current input token, if not, an error occurs.
LL(1) Parsing : First Sets • First Sets • Let X be a grammar symbol (a terminal or non-terminal) or ε. Then the set First(X) consisting of terminals, and possibly ε, is defined as follows
LL(1) Parsing : First Sets • e.g. for the grammar
LL(1) Parsing : Follow Sets • Follow Sets • Given a non-terminal A, the set Follow(A), consisting of terminals, and possibly $, is defined as follows. • ε is never an element of Follow set
LL(1) Parsing : Follow Sets • e.g. for the grammar
LL(1) Parsing table • How to construct LL(1) parsing table
LL(1) grammar • A grammar is LL(1) if the following conditions are satisfied. • That is the LL(1) parsing table has at most one production in each table entry.
Mentioned issues • Left Recursion removal • Left Factoring
References • COMPILER CONSTRUCTION: Principles and Practice, • Kenneth C. Louden • Chapter 4 • http://www.cs.sjsu.edu/faculty/louden/cmptext/ • http://www.course.com/isbn=0-534-93972-4