forked from MarkusEble/Compilerbau25
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTAssignStmtNode.java
More file actions
42 lines (31 loc) · 989 Bytes
/
ASTAssignStmtNode.java
File metadata and controls
42 lines (31 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.compiler.ast;
import java.io.OutputStreamWriter;
import com.compiler.Symbol;
import com.compiler.Token;
public class ASTAssignStmtNode extends ASTStmtNode{
private Symbol identifier;
private ASTExprNode expr;
public ASTAssignStmtNode(Symbol identifier, ASTExprNode expr) {
super();
this.identifier = identifier;
this.expr = expr;
}
@Override
public void execute(OutputStreamWriter out) {
identifier.m_number = expr.eval();
}
@Override
public void codegen(com.compiler.CompileEnvIntf env) {
com.compiler.InstrIntf exprInstr = expr.codegen(env);
com.compiler.InstrIntf assignInstr = new com.compiler.instr.InstrAssign(identifier, exprInstr);
env.addInstr(assignInstr);
}
@Override
public void print(OutputStreamWriter outStream, String indent) throws Exception {
outStream.write(indent);
outStream.write("ASTAssignStmtNode ");
outStream.write(identifier.m_name);
outStream.write("\n");
expr.print(outStream, indent + " ");
}
}