|
input |
action
|
$E |
id + id * id $ |
expand by E  TE'
|
$E'T |
id + id * id $ |
expand by T  FT'
|
|
id + id * id $ |
expand by F  id
|
$E'T'id |
id + id * id $ |
pop id and ip++
|
$E'T' |
+ id * id $ |
expand by T'  ε |
$E' |
+ id * id $ |
expand by E'  +TE'
|
$E'T+ |
+ id * id $ |
pop + and ip++
|
$E'T |
id * id $ |
expand by T  FT'
|
|
|
|
Let us work out an example assuming that we have a parse table. We follow the predictive parsing algorithm which was stated a few slides ago. With input id
id * id , the predictive parser makes the sequence of moves as shown. The input pointer points to the leftmost symbol of the string in the INPUT column. If we observe the actions of this parser carefully, we see that it is tracing out a leftmost derivation for the input, that is, the productions output are those of a leftmost derivation. The input symbols that have already been scanned, followed by the grammar symbols on the stack (from the top to bottom), make up the left-sentential forms in the derivation.