Fifteenth work syntax-semantics translation

1. The syntax grammar G [E] is as follows: 

E→E+T | E-T | T 

T→T* F | T/F | F 

F→P^ F | P 

P → (E) | i 

  • Construct described in claim semantically attribute grammar analysis requirements (mainly generates four yuan write portion).

E->E1+T  emit{+,E.val,T.val,E,val }

E->E-T   emit{-,E.val,T.val,E,val }

E->T     emit{T.val,E,val }

T->T*F   emit{*,T.val,F.val,T.val}

T->T/F    emit{/,T.val,F.val,T.val}

T->F     emit{F.val,T.val}

F->P^F   emit{^,F.val,P.val,F.val}

F->P    emit{P.val,F.val}

P->(E)   

P->i   

2. (OPTIONAL) third experiment: Syntax-Semantics translator

Claim:

  • To achieve the above expression grammar analysis by operator priority syntax-directed translation process.
  • Upon completion of the second experiment (operator priority syntax analysis) on the semantic analysis program design.
  • The final output is equivalent to the test Quaternion intermediate code sequence.

Such as

Input: a + b * c, the output

(*,b,c,T1)

(+,a,T1,T2)

Input: b * (c + b) * d, the output

(*,b,c,T1)

(*,b,d,T2)

(+, T1, T2, T3)

Guess you like

Origin www.cnblogs.com/fqy1028/p/12058412.html