예제 #1
0
 @Override
 public void close() throws IOException {
   if (closed) return;
   closed = true;
   source.close();
   buffer.clear();
 }
예제 #2
0
파일: Pascal.java 프로젝트: KukaTails/tpsc
  /**
   * Compile or interpret a Pascal source program.
   *
   * @param operation either "compile" or "execute".
   * @param filePath the source file path.
   * @param flags the command line flags.
   */
  public Pascal(String operation, String sourcePath, String inputPath, String flags) {
    try {
      intermediate = flags.indexOf('i') > -1;
      xref = flags.indexOf('x') > -1;

      source = new Source(new BufferedReader(new FileReader(sourcePath)));
      source.addMessageListener(new SourceMessageListener());

      parser = FrontendFactory.createParser("Pascal", "top-down", source);
      parser.addMessageListener(new ParserMessageListener());

      backend = BackendFactory.createBackend(operation, inputPath);
      backend.addMessageListener(new BackendMessageListener());

      parser.parse();
      source.close();

      if (parser.getErrorCount() == 0) {
        symTabStack = parser.getSymTabStack();

        SymTabEntry programId = symTabStack.getProgramId();
        iCode = (ICode) programId.getAttribute(ROUTINE_ICODE);

        if (xref) {
          CrossReferencer crossReferencer = new CrossReferencer();
          crossReferencer.print(symTabStack);
        }

        if (intermediate) {
          ParseTreePrinter treePrinter = new ParseTreePrinter(System.out);
          treePrinter.print(symTabStack);
        }
        backend.process(iCode, symTabStack);
      }
    } catch (Exception ex) {
      System.out.println("***** Internal translator error. *****");
      ex.printStackTrace();
    }
  }
예제 #3
0
 public void close() {
   SRC.close();
 }