The inverse Polish expression of expression A:=B*(CD)/DA:=B∗(C−D)/D

Expression A: = B ∗ (C − D) / DA:=B*(CD)/DA:=B(CD ) / D inverse Polish expression

Inverse Polish is also a postfix expression, so the answer to this question is:

A B C D − ∗ D / : = ABCD-*D/:= ABCDD/:=

Quaternion

The quaternion is actually an equivalent representation of a "three-address statement". Its general form is:
(op, arg 1, arg 2, result) (op,arg1,arg2,result)( o p ,arg1,arg2,r e s u l t )
Among them, op is a binary (also unary or zero-element) operator; arg1 and arg2 are its two operation (or operation) objects respectively, which can be variables, constants or system definitions The name of the temporary variable; the result of the operation will be placed in the result. The quaternion can also be written in a form similar to the PASCAL language assignment statement:
result := arg 1 result := arg1result=a r g 1 on opo p arg 2 arg2a r g 2 What
needs to be pointed out is that each quaternion can only have one operator, so a complex expression must be represented by a sequence of multiple quaternions. For example, the expression A+B*C can be written as the sequence
T 1 := B ∗ C T1:=B*CT1=BC
T 2 ∶ = A + T 1 T2∶=A+T1 T2=A+T 1
Among them, T1, T2 are temporary variable names generated by the compilation system. When op is a unary or zero-element operator (such as unconditional transfer), arg2 and even arg1 should default, that is result:=op arg1 or op result; the corresponding general form is:(op, arg 1,,
result) (op ,arg1,,result)( o p ,arg1,,result)

( o p , , , r e s u l t ) (op,,,result) ( o p ,,,r e s u l t )
In the actual quaternion, op is often represented by an integer (operator code), which may have more than one attribute attached. For example, addition operations can be divided into fixed-point addition and floating-point addition, and we can distinguish these two additions with different integer values. As for the operands arg1, arg2 and the result field in the quaternion, they can be pointers to an item in the symbol table, or the serial number of a temporary variable. Therefore, in the actual translation process, it needs to be Check and fill the symbol table accordingly. In this chapter, since we are only discussing in principle, we assume that temporary variables come from an inexhaustible set, instead of pursuing economics.

Expression A: = B ∗ (C − D) / DA:=B*(CD)/DA:=B(CD ) / D' s quaternion representation

  1. ( − , C , D , t 1 ) (-,C,D,t1) (,C,D,t 1 )
  2. ( ∗ , B , t 1 , t 2 ) (*,B,t1,t2) (,B,t 1 ,t2)
  3. ( / , / t 2 , D , t 3 ) (/,/t2,D,t3) (/,/t2,D,t 3 )
  4. ( : = , t 3 , _ , A ) (:=,t3,\_,A) (:=,t 3 ,_,A)

Express the above quaternion in DAG

DAG diagram

Guess you like

Origin blog.csdn.net/qq_41870170/article/details/114686365