-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStmt.java
More file actions
45 lines (38 loc) · 1.56 KB
/
Stmt.java
File metadata and controls
45 lines (38 loc) · 1.56 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
package rei;
import java.util.List;
public abstract class Stmt {
public interface Visitor<R> {
R visitPrintStmt(Print stmt);
R visitAssignStmt(Assign stmt);
R visitIfStmt(If stmt);
R visitBlockStmt(Block stmt);
}
public abstract <R> R accept(Visitor<R> visitor);
public static class Print extends Stmt {
public final Expr expression;
public Print(Expr expression) { this.expression = expression; }
public <R> R accept(Visitor<R> visitor) { return visitor.visitPrintStmt(this); }
}
public static class Assign extends Stmt {
public final Token name;
public final Expr value;
public Assign(Token name, Expr value) { this.name = name; this.value = value; }
public <R> R accept(Visitor<R> visitor) { return visitor.visitAssignStmt(this); }
}
public static class If extends Stmt {
public final Expr condition;
public final Stmt thenBranch;
public final Stmt elseBranch;
public If(Expr condition, Stmt thenBranch, Stmt elseBranch) {
this.condition = condition;
this.thenBranch = thenBranch;
this.elseBranch = elseBranch;
}
public <R> R accept(Visitor<R> visitor) { return visitor.visitIfStmt(this); }
}
public static class Block extends Stmt {
public final java.util.List<Stmt> statements;
public Block(java.util.List<Stmt> statements) { this.statements = statements; }
public <R> R accept(Visitor<R> visitor) { return visitor.visitBlockStmt(this); }
}
}