随笔分类 -  编译原理

摘要:1: package compiler; 2: //竟然没有对符号表检查大小,会溢出的。 3: 4: import java.io.IOException; 5: 6: public class SymbolTable { 7: 8: /** 9: * 当前名字表项指针(有效的符号表大小)table size 10:... 阅读全文
posted @ 2014-02-22 16:25 姜楠 阅读(1121) 评论(0) 推荐(0)
摘要:1: package compiler; 2: 3: /** 4: * 采用全局变量sym来存储符号码,并用全局变量id和num来传递语义值 5: * 6: * @author jiangnan 7: * 8: */ 9: public class Symbol { 10: 11: //各类符号码 12: ... 阅读全文
posted @ 2014-02-22 16:23 姜楠 阅读(761) 评论(0) 推荐(0)
摘要: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 cla... 阅读全文
posted @ 2014-02-22 16:21 姜楠 阅读(768) 评论(0) 推荐(0)
摘要:1: package compiler; 2: 3: import java.io.IOException; 4: import java.util.BitSet; 5: 6: /** 7: * 语法分析器。 这是PL/0分析器中最重要的部分, 在语法分析的过程中嵌入了语法错误检查和目标代码生成。 8: * 9: * @author... 阅读全文
posted @ 2014-02-22 16:20 姜楠 阅读(1897) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2014-02-22 16:15 姜楠 阅读(1599) 评论(0) 推荐(0)
摘要: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: ... 阅读全文
posted @ 2014-02-22 16:13 姜楠 阅读(796) 评论(0) 推荐(0)
摘要: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代码解释器(含代码生成函数) 12:... 阅读全文
posted @ 2014-02-22 16:12 姜楠 阅读(1076) 评论(0) 推荐(0)
摘要: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 Str... 阅读全文
posted @ 2014-02-22 16:10 姜楠 阅读(560) 评论(0) 推荐(0)
摘要: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 ed... 阅读全文
posted @ 2014-02-22 16:08 姜楠 阅读(1159) 评论(0) 推荐(1)
摘要:包 lexer 是词法分析器的代码的扩展。类 Tag 定义了各个词法单元对应的常量。 1: package lexer; 2: public class Tag { 3: public final static int 4: AND = 256 , BASIC = 257 , BREAK = 258 , DO = 259 , ELSE = 260... 阅读全文
posted @ 2014-01-17 22:26 姜楠 阅读(831) 评论(0) 推荐(1)
摘要:程序的执行从类Main的方法main开始。方法main创建了一个词法分析器和一个语法分析器,然后调用语法分析器中的方法program。 1: package main; 2: import java.io.*; 3: import lexer.*; 4: import praser.*; 5: public class Main{ 6: public s... 阅读全文
posted @ 2014-01-17 19:57 姜楠 阅读(514) 评论(0) 推荐(0)
摘要:这个语言的一个程序由一个块组成,该块中包含可选的声明和语句。语法符号basic表示基本类型。program –> blockblock –> { decls stmts }decls -> desls decl | εdecl -> type id;type -> type [num] | basicstmts -> stmts stmt | ε把复制当做一个语句(而不是表达式中的运算符)可以简化翻译工作。stmt -> loc=bool; | if(bool) stmt | if(bool) stmt else stmt | while(bool) 阅读全文
posted @ 2014-01-17 19:48 姜楠 阅读(1548) 评论(0) 推荐(0)
摘要:编译实践-PL\0编译系统实现 姓名: 专业: 计算机科学与技术 学院: 软件学院 提交时间: 2013年12月25日 北京航空航天大学·软件学院 编译实践-PL\0编译系统实现 实验要求 以个人为单位进行开发,不得多人合作完成。 共32个学时。个人无计算机者可以申请上机机时。 细节要求: 输入:符合PL/0文法的源程序(自己要... 阅读全文
posted @ 2013-12-27 17:09 姜楠 阅读(14177) 评论(4) 推荐(7)