Answer the following questions about the context-free grammar defined below.
The symbols , ;, begin, and end are assumed to be terminals.
We will work with the following augmented grammar:
First, we build
, the collection of
items for the augmented grammar: (the third
column will be explained later)
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Then, we fill up the 'Action' part of the parse table, that is the part of the table from which, given a
state
and an input symbol
, we will be able to know if we have to shift the input symbol and
with which state or if we have to reduce thanks to a particular production. In this last case, we push on
the stack the left-hand of the production with a state given by the 'Next' part of the parse table (part
that we will build afterwards). The state
is built from
. The analysis actions for the state
are determined as follows:
We need the following sets:
FOLLOW
FOLLOW
FOLLOW
For
in
, we have
filled with 'reduce with
'.
For
in
, we have
filled with 'reduce with
'.
Then we build the 'Next' part of the parse table. For state
and for any non-terminal
, we have,
if
, alors
.
This grammar becomes SLR(1) if we eliminate the conflict for ';' in
by eliminating it from
FOLLOW
.