-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnaryNode.java
51 lines (43 loc) · 1.08 KB
/
UnaryNode.java
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
43
44
45
46
47
48
49
50
51
class UnaryNode extends Ast {
static final int dereference = 1;
static final int convertToReal = 2;
static final int notOp = 3;
static final int negation = 4;
public UnaryNode (int nt, Type t, Ast b) {
super(t);
nodeType = nt;
child = b;
}
public int nodeType;
public Ast child;
public String toString() { return "Unary node " + nodeType +
"(" + child + ")" + type; }
public void genCode () {
switch(nodeType) {
case dereference:
child.genCode();
System.out.println("dereference " + type);
break;
case convertToReal:
child.genCode();
System.out.println("convert to real" + type);
break;
case notOp:
child.genCode();
System.out.println("not op " + type);
break;
case negation:
child.genCode();
System.out.println("numeric negation " + type);
break;
}
}
public void branchIfTrue (Label lab) throws ParseException {
genCode();
System.out.println("Branch if True " + lab);
}
public void branchIfFalse (Label lab) throws ParseException {
genCode();
System.out.println("Branch if False " + lab);
}
}