• PL/0编译器(java version)–PL0.java


       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:      public static final String tableFile = "d:\table.txt";
      16:      public static final String runtimeFile = "d:\runtime.txt";
      17:      public static final String errFile = "d:\error.txt";
      18:      public static final String inputFile="d:\input.txt";
      19:      public static BufferedWriter pcodeWriter;                 //输出虚拟机代码
      20:      public static BufferedWriter runtimeWriter;               //输出结果
      21:      public static BufferedWriter tableWriter;                //输出名字表
      22:      public static BufferedWriter errWriter;                   //输出错误信息
      23:   
      24:      public Praser praser;
      25:   
      26:      public PL0(String filepath) {
      27:          Scanner scan = new Scanner(filepath);
      28:          praser = new Praser(scan,//词法分析器
      29:                  new SymbolTable(),//名字表
      30:                  new Interpreter());
      31:      }
      32:   
      33:      public boolean compile() {
      34:          try {
      35:              pcodeWriter = new BufferedWriter(new FileWriter(pcodeFile));
      36:              tableWriter = new BufferedWriter(new FileWriter(tableFile));
      37:              runtimeWriter = new BufferedWriter(new FileWriter(runtimeFile));
      38:              errWriter = new BufferedWriter(new FileWriter(errFile));
      39:              praser.nextsym();                                    //前瞻分析需要预先读入一个符号
      40:              praser.parse();                                        //开始语法分析过程(连同语法检查,目标代码生成)
      41:              pcodeWriter.close();
      42:              tableWriter.close();
      43:              runtimeWriter.close();
      44:              errWriter.close();
      45:          } catch (Exception e) {
      46:              e.printStackTrace();
      47:              System.out.println("***compile error***");
      48:          } finally {
      49:   
      50:          }
      51:          //编译成功是指完成编译过程并且没有错误
      52:          return (praser.myErr.errCount == 0);
      53:      }
      54:  }
  • 相关阅读:
    关于selenium中的sendKeys()隔几秒发送一个字符
    C#使用.net.mail配置163邮箱报错:不允许使用邮箱名称。 服务器响应为:authentication is required,smtp9,DcCowABHK4UYE11W2k6fAQ--.52196S2 1448940312
    Git一个本地仓库同时推送到多个远程仓库
    MySQL中的字符数据存储
    在IIS中启用net.tcp传输协议
    MS CRM 2016 二次开发知识点
    微软 CRM 2016 自定义视图顶部按钮
    CodeSmith7.0.2连接Oracle10.2
    使用Entity framework框架执行存储过程
    SQL建表公共字段脚本
  • 原文地址:https://www.cnblogs.com/ZJUT-jiangnan/p/3560954.html
Copyright © 2020-2023  润新知