?? sourceprinter.java
字號:
package jeex.tiny;
import java.io.*;
import java.util.*;
import jeex.tiny.Tree.*;
/**
* Prints out a tiny source file.
*/
class SourcePrinter extends Tree.Visitor {
PrintStream out = System.out;
int indent = 0;
SourcePrinter(PrintStream out) {
this.out = out;
}
SourcePrinter() {
this.out = System.out;
}
void _case(StmtSeq tree) {
Vector v = tree.statements;
for(int i = 0; i < v.size(); i++) {
Tree tree1 = (Tree)v.get(i);
tree1.visit(this);
if (i == (v.size() - 1)) // the last statement
out.println();
else
out.println(";");
}
}
void _case(IfStmt tree) {
indent();
out.print("if ");
tree.condition.visit(this);
out.println(" then");
indent ++;
tree.thenPart.visit(this);
if (tree.elsePart != null) {
indent --; indent();
out.println("else");
indent ++;
tree.elsePart.visit(this);
}
indent --; indent();
out.print("end");
}
void _case(RepeatStmt tree) {
indent();
out.println("repeat");
indent ++;
tree.stmtSeq.visit(this);
indent --;indent();
out.print("until ");
tree.condition.visit(this);
}
void _case(AssignStmt tree) {
indent();
out.print(tree.ident);
out.print(" := ");
tree.expr.visit(this);
}
void _case(ReadStmt tree) {
indent();
out.print("read ");
out.print(tree.ident);
}
void _case(WriteStmt tree) {
indent();
out.print("write ");
tree.expr.visit(this);
}
void _case(Expr tree) {
tree.first.visit(this);
if (tree.second != null) {
out.print(tree.op == Tokens.LT ? " < " : " = ");
tree.second.visit(this);
}
}
void _case(ParExpr tree) {
out.print("(");
tree.expr.visit(this);
out.print(")");
}
void _case(Operation tree) {
tree.left.visit(this);
out.print(" " + TokenUtil.tokenToString(tree.op) + " ");
tree.right.visit(this);
}
void _case(Ident tree) {
out.print(tree.name);
}
void _case(Literal tree) {
out.print(tree.value);
}
void _case(ErrorTree tree) {
out.print("ERROR");
}
private void indent() {
for(int i = 0; i < indent; i++)
out.print(" ");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -