Compiler theory Quiz jobs thirteen ------- operator priority analysis

1. Connect jobs (P121 Exercise 1), to complete 4), 5) two steps.

S1--->#S#

S--->a | ^ | (T)

T--->T,S | S

1) calculating and FIRSTVT LASTVT.

2) find a three relationships right.

3) construction operator precedence table.

4) whether the operator priority to grammar?

5) given input string (a, (a, a)) # of operator precedence analysis.

 

Stack

relationship

Input string

action

#

(a,(a,a))#

Moved into

#(

a,(a,a))#

Moved into

#(a

,(a,a))#

Reduction

#(N

,(a,a))#

Moved into

#(N,

(a,a))#

Moved into

#(N,(

a,a))#

Moved into

#(N,( a

,a))#

Reduction

#(N,( N,

a))#

Moved into

#(N,( N, a

))#

Reduction

#(N,( N, N

))#

Reduction

#(N,( N

=

))#

Moved into

#(N,(N)

)#

Reduction

#(N,N

              >

)#

Reduction

#(N

=

)#

Moved into

#(N)

#

Reduction

# N

=

#

Moved into

# N #

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2. Try parser written bottom-up.

Expression can be written only partially.

 

3. The following statement is given ternary type, quaternary style and Reverse Polish Notation.

a*b+(c-d)/e 

Three yuan type:

(1) (* a,b)

(2) (- c,d)

(3) (/ (2),e)

(4) (+ (1),(3))

Quaternion type:

(1) (* ,a,b,t1)

(2) (- ,c,d,t2)

(3) (/ ,t2,e,t3)

(4) (+ t1, t3, t4)

Reverse Polish Notation:

ab * cd-e / +

Guess you like

Origin www.cnblogs.com/xiaoAP/p/12015711.html