⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compiler.java

📁 java语言开发的基于tiny语言的编译器
💻 JAVA
字号:

package jeex.tiny;

import java.io.*;
/**
 * Main class.
 */
class Compiler {
	public static void main(String[] args) {
		if (args.length <= 0) {
			System.err.println("Usage: Compiler filename");
			System.exit(1);
		}
		//create scanner
		Scanner s = null;
		try {
			FileInputStream in = new FileInputStream(args[0]);
			s = new Scanner(in);
		} catch(FileNotFoundException e) {
			System.err.println(args[0] + " not found,exit...");
			System.exit(1);
		} catch(IOException e2) {
			System.err.println("read " + args[0] + " error,exit...");
			System.exit(1);
		}
		//parsing: build abstract syntax tree
		Parser parser = new Parser(s);		
		Tree prog = parser.Program();
		if (Log.count()>0) {
			System.err.println("compile " + args[0] + "failed");
			System.exit(1);
		}
		//generate code
		Code code = new Code();		
		Gen gen = new Gen(code);
		gen.main(prog);
		if (Log.count()>0) {
			System.err.println("compile " + args[0] + "failed");
			System.exit(1);
		}
		//write to file
		code.write("a.txt");
		
		System.exit(0);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -