13 compiler theory bottom-up parsing

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.

Symbols Stack

Input string

action

#

i+i*i#

Moved into

#i

+i*i#

Reduction

#F

+i*i#

Reduction

#T

+i*i#

Reduction

#E

+i*i#

Moved into

#E+

i*i#

Moved into

# E + i

*i#

Reduction

#E+F

*i#

Reduction

#E+T

*i#

Moved into

#E+T*

i#

Moved into

#E+T*i

#

Reduction

#E+T*F

#

Reduction

#E+T

#

Reduction

#E

#

accept

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.P121 Exercise 1 (1) (2).

1) calculating and FIRSTVT LASTVT.

2) find a three relationships right.

3) construction operator precedence table.

(1

FIRSTVT(S) = {a , ^ , ( }

FIRSTVT(T) = {,, a , ^ , ( }

LASTVT(S) = {a , ^ , ) }

Lastva (T) = {,, the, ^,)}

(2

=

(T)

#S#

#S

(T

,S

S#

T)

T,

 

 

 

 

 

(3

 

a

^

,

(

)

#

a

 

 

>

 

^

 

 

>

 

,

<

<

>

<

>

 

(

<

=

 

)

 

 

>

 

#

 

 

=

Guess you like

Origin www.cnblogs.com/longlog/p/12038575.html