Professional Documents
Culture Documents
Lecture 9 - Predictive Parsing
Lecture 9 - Predictive Parsing
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Predictive Parsing
Lecture 9
Section 4.4
Assignment
Robb T. Koether
Hampden-Sydney College
Outline
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Predictive Parsing
Assignment
Assignment
By definition, FIRST() = .
For the string = X1 X2 . . . Xn ,
Let k be the largest integer for which X1 , X2 , . . . , and Xk
are nullable.
Then
FIRST() = FIRST(X1 ) . . . FIRST(Xk+1 ).
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Nullable
No
Yes
No
Yes
No
FIRST
{(, id, num}
{+}
{(, id, num}
{}
{(, id, num}
FOLLOW
{$, )}
{$, )}
{$, ), +}
{$, ), +}
{, $, ), +}
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
(
E T E0
E0 + T E0
id
E T E0
T F T0
T F T0
F num
F id
E0
T F T0
T0
num
E T E0
T0 * F T0
E0
T0
F (E)
T0
Predictive Parsing
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Predictive
Parsing
Assignment
Otherwise, it is an error.
Otherwise, it is an error.
Otherwise, it is an error.
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
F
)E)
)E
) E0 T
) E0 T 0 F
) E0 T 0 id
) E0 T 0
) E0
) E0 T +
) E0 T
Input
( id + num ) * id $
( id + num ) * id $
( id + num ) * id $
( id + num ) * id $
id + num ) * id $
id + num ) * id $
id + num ) * id $
id + num ) * id $
+ num ) * id $
+ num ) * id $
+ num ) * id $
num ) * id $
Example
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
) E0 T 0 F
) E0 T 0 num
) E0 T 0
) E0
)
F*
F
id
Input
num ) * id $
num ) * id $
) * id $
) * id $
) * id $
* id $
* id $
id $
id $
$
$
$
Assignment
Predictive
Parsing
Robb T.
Koether
The Parse
Table Entries
The Parse
Table
Predictive
Parsing
Assignment
Homework
The grammar
R R R | RR | R* | (R) | a | b
generates all regular expressions on the alphabet
= {a, b}.
Using FIRST and FOLLOW from the exercise of the
previous lecture, construct a parse table for this
grammar.
Parse the expression ab* (a b).