main.java
来自「实现的一个简单的语言编译器,可以编译类JAVA 的小语言」· Java 代码 · 共 63 行
JAVA
63 行
package edu.ustc.cs.compile.parser;
import java.io.File;
import org.eclipse.jdt.core.dom.ASTNode;
import edu.ustc.cs.compile.parser.expr.ExprParser;
import edu.ustc.cs.compile.platform.interfaces.CheckerException;
import edu.ustc.cs.compile.platform.interfaces.InterRepresent;
import edu.ustc.cs.compile.platform.interfaces.ParserException;
import edu.ustc.cs.compile.platform.util.ASTView.core.ASTViewer;
public class Main {
private static boolean viewAST = true;
/**
* @param args
*/
public static void main(String[] args) {
//runPart1();
runPart2();
}
public static void runPart2() {
boolean viewAST = true;
String srcFileName = "E:/student/PB05011/PB05210242/test/quicksort.mj";
File srcFile = new File(srcFileName);
ASTNode block;
ExprParser parser = new ExprParser();
InterRepresent ir = null;
try {
ir = parser.doParse(srcFile);
} catch (ParserException e) {
e.printStackTrace();
System.exit(-1);
}
if (!parser.getResult()) {
System.out.println("[NOTICE] Vital error found in the parser,compilering stopped.....");
System.exit(-1);
}
// 调用ASTViewer显示生成的AST
if (viewAST){
ASTViewer astviewer = new ASTViewer((ASTNode)ir.getIR());
astviewer.show();
}
Checker socheck = new Checker();
try{
if (!socheck.check(ir)) System.exit(-1);
}catch (CheckerException e) {
e.printStackTrace();
System.exit(-1);
}
System.out.println(" 前端:PB05210242王卅");
// System.out.println("Checker has not found any errors.");
//} else {
// System.out.println("Checker has found some errors.");
//}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?