Fourteenth job: operator priority analysis

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

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) find a three relationships right.

=

(T)

#S#

 

<

#S

,S

(T

 

>

S#

T)

T,

3) construction operator precedence table.

 

 

4) whether the operator priority to grammar?

Yes

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

 

 

2. Try parser written bottom-up.

Expressions can be written only part

 

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

a*b+(c-d)/e 

 

Three yuan:

(1) (*,a,b)

(2) (- , c ,d)

(3) (/ ,e,(2))

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

 

Four yuan:

(1) t1:=a*b

(2) t2:=(c-d)

(3) t3:= t2/e

(4) t4: = t1 + t3

 

Reverse Polish Notation:

a*b+(c-d)/e ->cd-e/ab*+

Guess you like

Origin www.cnblogs.com/laylay/p/12029240.html