-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathControlExpr.java
More file actions
75 lines (65 loc) · 1.79 KB
/
Copy pathControlExpr.java
File metadata and controls
75 lines (65 loc) · 1.79 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cwp.ast;
import cwp.lexer.Token;
import cwp.parser.Controls;
import java.util.ArrayList;
public class ControlExpr extends Expr {
ArrayList<Expr> args;
ArrayList<Expr> body;
Controls.Type type;
public ControlExpr(Token initTok, ArrayList<Expr> args, ArrayList<Expr> body, Controls.Type type) {
super(initTok);
this.args = args;
this.body = body;
this.type = type;
}
@Override
public String toString() {
return initTok.toString();
}
@Override
/* public String gen() {
*if (type == Controls.Type.FLAT) {
return genFlat();
}
if (type == Controls.Type.MAP) {
return genMap();
}
return genVec();
}*/
public String gen() {
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(initTok.str);
sb.append(" ");
if (type == Controls.Type.VEC) {
sb.append("[");
} else if (type == Controls.Type.MAP) {
sb.append("{");
}
// args
for (int i = 0; i < args.size() - 1; i++) {
sb.append(args.get(i).gen());
sb.append(" ");
}
if (!args.isEmpty()) {
sb.append(args.get(args.size() - 1).gen());
}
if (type == Controls.Type.VEC) {
sb.append("]");
} else if (type == Controls.Type.MAP) {
sb.append("}");
}
if (!args.isEmpty())
sb.append(" ");
// body
for (int i = 0; i < body.size() - 1; i++) {
sb.append(body.get(i).gen());
sb.append(" ");
}
if (!body.isEmpty()) {
sb.append(body.get(body.size() - 1).gen());
}
sb.append(")");
return sb.toString();
}
}