3 address code = 3AC = TAC
The stmts of 3AC are:
TACBlock -> []TACStmt
-
TACStmt (INTERFACE) components: id [int] line [int] ToString() string
-
Label (STRUCT)
-
Assignment (INTERFACE) components: Assignee [SimpleValue]
CompoundAssignment (STRUCT) components: Left [SimpleValue] Right [SimpleValue] Operator [ArithmeticOperator]
SimpleAssignment (STRUCT) components: Val [Value]
-
Jump statements (INTERFACE)
Conditional jump statements (STRUCT) components: Condition [BooleanExpression] Target [Label]
Unconditional jump statements (STRUCT) components: Target [Label]
-
Method Dcl (STRUCT) components: Name Block [TACBlock]
-
Method Call (STRUCT) components: Name
-
Value (INTERFACE)
SimpleValue (INTERFACE) components: Cast [CastType]
Temporal (STRUCT) HeapPointer (STRUCT) StackPointer (STRUCT) Literal (STRUCT) components: Val [int/float]
IndexedValue (INTERFACE) components: Index [SimpleValue]
HeapIndexed (STRUCT) StackIndexed (STRUCT)
-
ArithmeticOperator (Enum) [+, -, *, /, %]
-
CastType (Enum) [float]
-
BooleanExpression (STRUCT) components: Left [SimpleValue] Right [SimpleValue] Operator [BooleanOperator]
-
BooleanOperator (Enum) [==, !=, <, >, <=, >=]
-
print (STRUCT) components: Val [SimpleValue]
-
Comment (STRUCT) components: Val [string]
-
Basic ideas:
- TACBlock is just a list of TACStmts
- All values must provide a prop named "Cast" which is a CastType
- CastType <-> Enum
type TACStmt interface {
ToString() string
}
std lib: printString compareString
- Value system 1.1. Primitives: int, double, bool, char
- Variable asgmt