PL/0编译器(java version) - Err.java】的更多相关文章

1: package compiler; 2:   3: import java.io.BufferedWriter; 4:   5: public class Err { 6:   7: public int errCount = 0; 8: public static final String[] errInfo = new String[]{ 9: "", 10: "1.应是=而不是:=", 11: "2.=后应为数", 12: "…
1: /* 2: * To change this license header, choose License Headers in Project Properties. 3: * To change this template file, choose Tools | Templates 4: * and open the template in the editor. 5: */ 6: package compiler; 7:   8: import fileSystem.fileFil…
花了几天时间,把清华版的<编译原理>一书中的PL/0编译器实践了一遍.颇有收获,记录如下: 理解代码的技巧,如何理解一份代码,比如这个程序,其逻辑相对于一般程序就比较复杂了,如何翻译,虚拟机代码执行时数据栈如何变化等,都比较抽象,很难在大脑中有形象的感受,这时,最好的办法就是单步调试,比如vs2015就很强大,还能监视变量,绘制流程图,等等. 对代码的追求,除了九月十月,感觉最近一段时间一直在学习而不是实践,一方面由于自己习惯不好,被动接受,缺乏思考,比如代码是不是可以更简洁,更优雅:另一方面…
1: package compiler; 2:   3: import java.io.IOException; 4: import java.util.BitSet; 5:   6: /** 7: * 语法分析器. 这是PL/0分析器中最重要的部分, 在语法分析的过程中嵌入了语法错误检查和目标代码生成. 8: * 9: * @author jiangnan 10: * 11: */ 12: public class Praser { 13:   14: /** 15: * 当前符号,由next…
1: package compiler; 2: //竟然没有对符号表检查大小,会溢出的. 3:   4: import java.io.IOException; 5:   6: public class SymbolTable { 7:   8: /** 9: * 当前名字表项指针(有效的符号表大小)table size 10: */ 11: public int tablePtr = 0; 12: /** 13: * 符号表的大小 14: */ 15: public static final…
1: package compiler; 2:   3: import java.io.BufferedReader; 4: import java.io.FileNotFoundException; 5: import java.io.FileReader; 6: import java.util.Arrays; 7:   8: public class Scanner { 9:   10: public int lineCnt=0; 11: private char curCh = ' ';…
1: package compiler; 2:   3: import java.io.BufferedWriter; 4: import java.io.FileWriter; 5:   6: /** 7: * 组织输入输出接口 8: * 9: * @author jiangnan 10: */ 11: public class PL0 { 12:   13: 14: public static final String pcodeFile = "d:\\pcode.txt"; 15…
1: package compiler; 2:   3: import java.io.BufferedReader; 4: import java.io.BufferedWriter; 5: import java.io.IOException; 6: import java.util.Arrays; 7: import java.util.logging.Level; 8: import java.util.logging.Logger; 9:   10: /** 11: * 类P-code…
1: package compiler; 2:   3: /** 4: * 采用全局变量sym来存储符号码,并用全局变量id和num来传递语义值 5: * 6: * @author jiangnan 7: * 8: */ 9: public class Symbol { 10:   11: //各类符号码 12: public static final int nul = 0; //NULL 13: public static final int ident = 1; //标识符 14: pub…
1: package compiler; 2:   3: /** 4: * //虚拟机指令 5: * 6: * @author jiangnan 7: * 8: */ 9: public class Pcode { 10:   11: public Pcode(int f, int l, int a) { 12: this.f = f; 13: this.l = l; 14: this.a = a; 15: } 16: public static final int LIT = 0; 17: p…