Java Reference
In-Depth Information
The row of entries for state 0 is derived from item set s
0
.
{ By step 2a of Algorithm 3.11, the transition goto(s
0
,
(
) = s
4
implies Action[0,
(
] = s4, and goto(s
0
,
id
) = s
5
implies Action[0,
id
] = s5. The s4 means \shift
the next input symbol
(
onto the stack and go into state 4"; the s5 means \shift
the next input symbol
id
onto the stack and go into state 5."
The row of entries for state 1 is derived from item set s
1
:
{ By step 2a, the transition goto(s
1
,
+
) = s
6
implies Action[1,
+
] = s6. Remember,
the s6 means \shift the next input symbol
+
onto the stack and go into state 6".
{ By step 2b, because item set s
1
contains [E
0
::= E,
#
], Action[1,
#
] = accept. This
says, that if the parser is in state 1 and the next input symbol is the terminator
#
, the parser accepts the input string as being in the language.
The row of entries for state 2 is derived from item set s
2
:
{ By step 2a, the transition goto(s
2
,
*
) = s
7
implies Action[2,
*
] = s7.
{ By step 2c, the items
7
[E ::= T,
+/#
] imply two entries: Action[2,
#
] = r2 and
Action[2,
+
] = r2. These entries say that if the parser is in state 2 and the next
incoming symbol is either a
#
or a
+
, reduce the T on the stack to a E using
production rule 2: E ::= T.
The row of entries for state 3 is derived from item set s
3
:
{ By step 2c, the items [T ::= F,
+/*/#
] imply three entries: Action[3,
#
]= r4,
Action[3,
+
] = r4, and Action[3,
*
] = r4. These entries say that if the parser is
in state 3 and the next incoming symbol is either a
#
, a
+
, or a
*
reduce the F
on the stack to a T using production rule 4: T ::= F.
All other entries in rows 0, 1, 2, and 3 are left blank to indicate an error. If, for example,
the parser is in state 0 and the next incoming symbol is a
+
, the parser raises an error. The
derivations of the entries in rows 4 to 21 in the Action table (see Figure 3.7) are left as an
exercise.
Now let us consider the first four states of the Goto table:
The row of entries for state 0 is derived from item set s
0
:
{ By step 3a of Algorithm 3.11, the goto(s
0
, E) = 1 implies Goto[0, E] = 1, goto(s
0
,
T) = 2 implies Goto[0, E] = 4, and goto(s
0
, F) = 3 implies Goto[0, E] = 3. The
entry Goto[0, E] = 1 says that in state 0, once the parser scans and parses an
E, the parser goes into state 1.
The row of entries for state 1 is derived from item set s
1
. Because there are no
transitions on a non-terminal from item set s
1
, no entries are indicated for state 1 in
the Goto table.
The row of entries for state 2 is derived from item set s
2
. Because there are no
transitions on a non-terminal from item set s
2
, no entries are indicated for state 2 in
the Goto table.
7
Recall that the [E::=T,
+/#
] denotes two items: [E::=T,
+
] and [E::=T,
#
].
Search WWH ::
Custom Search