zoukankan      html  css  js  c++  java
  • 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:  }
  • 相关阅读:
    C++实现双缓冲
    [python]初探socket
    HTTP 状态代码表示什么意思?
    今天安装了麒麟系统
    初学python类
    python 如何在一个for循环中遍历两个列表
    python中xrange和range的异同
    再学python类(终结篇)
    常见浏览器兼容问题、盒模型2种模式以及css hack知识讲解
    原生JS实现瀑布流
  • 原文地址:https://www.cnblogs.com/ZJUT-jiangnan/p/3560954.html
Copyright © 2011-2022 走看看