1. Known grammar:
E→E+T | T
T→T*F | F
F → (E) | i
Reducible to handle as a string, a symbol string write 'i + i * i #' of "Shift - reduce" analysis.
2.P121 Exercise 1 (1) (2).
1) calculating and FIRSTVT LASTVT.
2) find a three relationships right.
3) construction operator precedence table.
-------------------------------------------------------------------------------------
solution:
1、
Symbol string | Input string | action |
# | i+i*i# | Moved into |
#i | +i*i# | Reduction |
#F | +i*i# | Reduction |
#T | +i*i# | Reduction |
#E | +i*i# | Reduction |
#E+ | +i*i# | Moved into |
# E + I | *i# | Moved into |
#E+F | *i# | Reduction |
#E+T | *i# | Reduction |
#E+T* | i# | Moved into |
#E+T*i | # | Moved into |
#E+T*F | # | Reduction |
#E+T | # | Reduction |
#E | # | Moved into |
2、
1) calculating and FIRSTVT LASTVT
S1→ #S#
S → a | L | (T)
T→ T,S|S
FIRSTVT(S)={a,Λ,(}
FIRSTVT(T)={,,a,Λ,(}
LASTVT(S)={a,Λ,)}
LASTVT(T)={,,a,Λ,)}
2) to find the three relationships
① =
(T)
#S#
------------------------------------
② <
#S
,S
(T
------------------------------------
③ >
S#
T)
T,
------------------------------------
3) construction operator precedence table
a | L. | ( | ) | , | # | |
a | > | > | > | |||
L. | > | > | > | |||
( | < | < | < | = | < | |
) | > | > | > | |||
, | < | < | < | > | > | |
# | < | < | < |