?? tree.java
字號:
package jeex.tiny;
import java.util.*;
/**
* Abstract syntax tree.
*/
abstract class Tree {
static int count = 0; // tree count
Tree() {
count ++;
}
void visit(Visitor v) {
v._case(this);
}
static class StmtSeq extends Tree {
Vector statements;
StmtSeq(Vector statements) {
this.statements = statements;
}
void visit(Visitor v) {
v._case(this);
}
}
static class IfStmt extends Tree {
Tree condition;
Tree thenPart;
Tree elsePart;
IfStmt(Tree condition,Tree thenPart,Tree elsePart) {
this.condition = condition;
this.thenPart = thenPart;
this.elsePart = elsePart;
}
void visit(Visitor v) {
v._case(this);
}
}
static class RepeatStmt extends Tree {
Tree condition;
Tree stmtSeq;
RepeatStmt(Tree condition,Tree stmtSeq) {
this.condition = condition;
this.stmtSeq = stmtSeq;
}
void visit(Visitor v) {
v._case(this);
}
}
static class AssignStmt extends Tree {
Tree ident;
Tree expr;
AssignStmt(Tree ident,Tree expr) {
this.ident = ident;
this.expr = expr;
}
void visit(Visitor v) {
v._case(this);
}
}
static class ReadStmt extends Tree {
Tree ident;
ReadStmt(Tree ident) {
this.ident = ident;
}
void visit(Visitor v) {
v._case(this);
}
}
static class WriteStmt extends Tree {
Tree expr;
WriteStmt(Tree expr){
this.expr = expr;
}
void visit(Visitor v) {
v._case(this);
}
}
static class Expr extends Tree {
Tree first;
int op;
Tree second;
Expr(Tree first,int op, Tree second) {
this.first = first;
this.op = op;
this.second = second;
}
void visit(Visitor v) {
v._case(this);
}
}
static class ParExpr extends Tree {
Tree expr;
ParExpr(Tree expr) {
this.expr = expr;
}
void visit(Visitor v) {
v._case(this);
}
}
static class Ident extends Tree {
String name;
Ident(String name) {
this.name = name;
}
void visit(Visitor v) {
v._case(this);
}
}
static class Literal extends Tree {
int value;
Literal(int value) {
this.value = value;
}
void visit(Visitor v) {
v._case(this);
}
}
static class Operation extends Tree {
int op;
Tree left;
Tree right;
Operation(int op,Tree left,Tree right) {
this.op = op;
this.left = left;
this.right = right;
}
void visit(Visitor v) {
v._case(this);
}
}
static class ErrorTree extends Tree {
ErrorTree() {
}
void visit(Visitor v) {
v._case(this);
}
}
/**
* Tree visitor used as base class of any concrete visitor.
*/
abstract static class Visitor {
void _case(StmtSeq tree) {
_case((Tree)tree);
}
void _case(IfStmt tree) {
_case((Tree)tree);
}
void _case(RepeatStmt tree) {
_case((Tree)tree);
}
void _case(AssignStmt tree) {
_case((Tree)tree);
}
void _case(ReadStmt tree) {
_case((Tree)tree);
}
void _case(WriteStmt tree) {
_case((Tree)tree);
}
void _case(Expr tree) {
_case((Tree)tree);
}
void _case(ParExpr tree) {
_case((Tree)tree);
}
void _case(Literal tree) {
_case((Tree)tree);
}
void _case(Ident tree) {
_case((Tree)tree);
}
void _case(Operation tree) {
_case((Tree)tree);
}
void _case(ErrorTree tree) {
_case((Tree)tree);
}
void _case(Tree tree) {
throw new RuntimeException("unexpected tree");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -