-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStmt.java
More file actions
100 lines (80 loc) · 2.29 KB
/
Copy pathStmt.java
File metadata and controls
100 lines (80 loc) · 2.29 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.util.List;
public abstract class Stmt {
public interface Visitor<R> {
R visitBlockStmt(BlockStmt stmt);
R visitExpressionStmt(ExpressionStmt stmt);
R visitIfStmt(IfStmt stmt);
R visitPrintStmt(PrintStmt stmt);
R visitVarDeclareStmt(VarDeclareStmt stmt);
R visitWhileStmt(WhileStmt stmt);
}
public abstract <R> R accept(Visitor<R> visitor);
}
class BlockStmt extends Stmt {
public final List<Stmt> statements;
public BlockStmt(List<Stmt> statements) {
this.statements = statements;
}
@Override
public <R> R accept(Visitor<R> visitor) {
return visitor.visitBlockStmt(this);
}
}
class ExpressionStmt extends Stmt {
public final Expr expression;
public ExpressionStmt(Expr expression) {
this.expression = expression;
}
@Override
public <R> R accept(Visitor<R> visitor) {
return visitor.visitExpressionStmt(this);
}
}
class IfStmt extends Stmt {
public final Expr condition;
public final Stmt thenBranch;
public final Stmt elseBranch;
public IfStmt(Expr condition, Stmt thenBranch, Stmt elseBranch) {
this.condition = condition;
this.thenBranch = thenBranch;
this.elseBranch = elseBranch;
}
@Override
public <R> R accept(Visitor<R> visitor) {
return visitor.visitIfStmt(this);
}
}
class PrintStmt extends Stmt {
public final Expr expression;
public PrintStmt(Expr expression) {
this.expression = expression;
}
@Override
public <R> R accept(Visitor<R> visitor) {
return visitor.visitPrintStmt(this);
}
}
class VarDeclareStmt extends Stmt {
public final Token name;
public final Expr initializer;
public VarDeclareStmt(Token name, Expr initializer) {
this.name = name;
this.initializer = initializer;
}
@Override
public <R> R accept(Visitor<R> visitor) {
return visitor.visitVarDeclareStmt(this);
}
}
class WhileStmt extends Stmt {
public final Expr condition;
public final Stmt body;
public WhileStmt(Expr condition, Stmt body) {
this.condition = condition;
this.body = body;
}
@Override
public <R> R accept(Visitor<R> visitor) {
return visitor.visitWhileStmt(this);
}
}