Пример #1
0
 public static void main(String args[]) throws Exception {
   Yylex l = null;
   parser p;
   try {
     if (args.length == 0) l = new Yylex(System.in);
     else l = new Yylex(new FileReader(args[0]));
   } catch (FileNotFoundException e) {
     System.err.println("Error: File not found: " + args[0]);
     System.exit(1);
   }
   p = new parser(l);
   /* The default parser is the first-defined entry point. */
   /* You may want to change this. Other options are: */
   /*  */
   try {
     pl.edu.mimuw.cloudatlas.interpreter.query.Absyn.Program parse_tree = p.pProgram();
     System.out.println();
     System.out.println("Parse Succesful!");
     System.out.println();
     System.out.println("[Abstract Syntax]");
     System.out.println();
     System.out.println(PrettyPrinter.show(parse_tree));
     System.out.println();
     System.out.println("[Linearized Tree]");
     System.out.println();
     System.out.println(PrettyPrinter.print(parse_tree));
   } catch (Throwable e) {
     System.err.println(
         "At line " + String.valueOf(l.line_num()) + ", near \"" + l.buff() + "\" :");
     System.err.println("     " + e.getMessage());
     System.exit(1);
   }
 }
Пример #2
0
 private void printForInit(ForInit s, CodeWriter w, PrettyPrinter tr, boolean printType) {
   boolean oldSemiColon = tr.appendSemicolon(false);
   boolean oldPrintType = tr.printType(printType);
   printBlock(s, w, tr);
   tr.printType(oldPrintType);
   tr.appendSemicolon(oldSemiColon);
 }
Пример #3
0
 public String printString() {
   return (PrettyPrinter.print(
       rs,
       new Printer<Object>() {
         @Override
         public String print(Object obj) {
           return obj.toString();
         }
       }));
 }
Пример #4
0
 public void print() {
   System.out.println(
       PrettyPrinter.print(
           rs,
           new Printer<Object>() {
             @Override
             public String print(Object obj) {
               return obj.toString();
             }
           }));
 }
Пример #5
0
  public static void main(String args[]) {
    try {
      System.out.println("Type in a tiny exp folowed by one or two Ctrl-d's:");
      Parser p = new Parser(new Lexer(new PushbackReader(new InputStreamReader(System.in), 1024)));

      Start tree = p.parse();
      NewEval.replaceUminus(tree);
      /* pretty-print */
      System.out.println("\nThe result of evaluating:");
      PrettyPrinter.print(tree);

      /* pre-eval to replace uminus */

      /* evaluate */
      System.out.print("\nis: ");
      PrettyPrinter.print(Evaluator.eval(tree));
      System.out.println("\n");

    } catch (Exception e) {
      System.out.println(e);
    }
  }
Пример #6
0
 public void prettyPrint() {
   try {
     // clear old problem messages
     problemsView.setText("");
     // update status view
     statusView.setText(" Parsing ...");
     LispExpr root = Parser.parse(textView.getText());
     statusView.setText(" Pretty Printing ...");
     String newText = PrettyPrinter.prettyPrint(root);
     textView.setText(newText);
     statusView.setText(" Done.");
   } catch (Error e) {
     System.err.println(e.getMessage());
     statusView.setText(" Errors.");
   }
 }
Пример #7
0
 /** Unparsing */
 public String toString() {
   return PrettyPrinter.render(this);
 }
Пример #8
0
 /** Pretty-printing */
 public void pretty(PrettyPrinter pp) {
   pp.print("STORE " + x);
 }
Пример #9
0
  /**
   * Run the pass <code>pass</code> on the job. Before running the pass on the job, if the job is a
   * <code>SourceJob</code>, then this method will ensure that the scheduling invariants are
   * enforced by calling <code>enforceInvariants</code>.
   */
  protected void runPass(Job job, Pass pass) throws CyclicDependencyException {
    // make sure that all scheduling invariants are satisfied before running
    // the next pass. We may thus execute some other passes on other
    // jobs running the given pass.
    try {
      enforceInvariants(job, pass);
    } catch (CyclicDependencyException e) {
      // A job that depends on this job is still running
      // an earlier pass.  We cannot continue this pass,
      // but we can just silently fail since the job we're
      // that depends on this one will eventually try
      // to run this pass again when it reaches a barrier.
      return;
    }

    if (getOptions().disable_passes.contains(pass.name())) {
      if (Report.should_report(Report.frontend, 1)) Report.report(1, "Skipping pass " + pass);
      job.finishPass(pass, true);
      return;
    }

    if (Report.should_report(Report.frontend, 1))
      Report.report(1, "Trying to run pass " + pass + " in " + job);

    if (job.isRunning()) {
      // We're currently running.  We can't reach the goal.
      throw new CyclicDependencyException(job + " cannot reach pass " + pass);
    }

    pass.resetTimers();

    boolean result = false;
    if (job.status()) {
      Job oldCurrentJob = this.currentJob;
      this.currentJob = job;
      Report.should_report.push(pass.name());

      // Stop the timer on the old pass. */
      Pass oldPass = oldCurrentJob != null ? oldCurrentJob.runningPass() : null;

      if (oldPass != null) {
        oldPass.toggleTimers(true);
      }

      job.setRunningPass(pass);
      pass.toggleTimers(false);

      result = pass.run();

      pass.toggleTimers(false);
      job.setRunningPass(null);

      Report.should_report.pop();
      this.currentJob = oldCurrentJob;

      // Restart the timer on the old pass. */
      if (oldPass != null) {
        oldPass.toggleTimers(true);
      }

      // pretty-print this pass if we need to.
      if (getOptions().print_ast.contains(pass.name())) {
        System.err.println("--------------------------------" + "--------------------------------");
        System.err.println("Pretty-printing AST for " + job + " after " + pass.name());

        PrettyPrinter pp = new PrettyPrinter();
        pp.printAst(job.ast(), new CodeWriter(System.err, 78));
      }

      // dump this pass if we need to.
      if (getOptions().dump_ast.contains(pass.name())) {
        System.err.println("--------------------------------" + "--------------------------------");
        System.err.println("Dumping AST for " + job + " after " + pass.name());

        NodeVisitor dumper = new DumpAst(new CodeWriter(System.err, 78));
        dumper = dumper.begin();
        job.ast().visit(dumper);
        dumper.finish();
      }

      // This seems to work around a VM bug on linux with JDK
      // 1.4.0.  The mark-sweep collector will sometimes crash.
      // Running the GC explicitly here makes the bug go away.
      // If this fails, maybe run with bigger heap.

      // System.gc();
    }

    Stats stats = getStats();
    stats.accumPassTimes(pass.id(), pass.inclusiveTime(), pass.exclusiveTime());

    if (Report.should_report(Report.time, 2)) {
      Report.report(
          2,
          "Finished "
              + pass
              + " status="
              + str(result)
              + " inclusive_time="
              + pass.inclusiveTime()
              + " exclusive_time="
              + pass.exclusiveTime());
    } else if (Report.should_report(Report.frontend, 1)) {
      Report.report(1, "Finished " + pass + " status=" + str(result));
    }

    job.finishPass(pass, result);
  }
Пример #10
0
 /** Pretty-printing */
 public void pretty(PrettyPrinter pp) {
   pp.binOp(a1, "-", a2);
 }
Пример #11
0
 @Override
 public String toString() {
   return PrettyPrinter.prettyPrint(this);
 }
Пример #12
0
 /** @inheritDoc */
 public void writeToStdOut(PrettyPrinter p) {
   p.printf("<JFieldDeclaration line=\"%d\"/>\n", line());
   p.indentRight();
   if (mods != null) {
     p.println("<Modifiers>");
     p.indentRight();
     for (String mod : mods) {
       p.printf("<Modifier name=\"%s\"/>\n", mod);
     }
     p.indentLeft();
     p.println("</Modifiers>");
   }
   if (decls != null) {
     p.println("<VariableDeclarators>");
     for (JVariableDeclarator decl : decls) {
       p.indentRight();
       decl.writeToStdOut(p);
       p.indentLeft();
     }
     p.println("<VariableDeclarators>");
   }
   p.indentLeft();
   p.println("</JFieldDeclaration>");
 }
Пример #13
0
 /**
  * Returns a human-readable representation of the given descriptor. For example, <code>
  * Ljava/lang/Object;</code> is converted into <code>java.lang.Object</code>. <code>(I[I)V</code>
  * is converted into <code>(int, int[])</code> (the return type is ignored).
  */
 public static String toString(String desc) {
   return PrettyPrinter.toString(desc);
 }
Пример #14
0
 public void writeToStdOut(PrettyPrinter p) {
   p.printf("<JForStatement line=\"%d\">\n", line());
   p.indentRight();
   p.printf("<Initialization>\n");
   p.indentRight();
   initialize.writeToStdOut(p);
   p.indentLeft();
   p.printf("</Initialization>\n");
   p.printf("<Termination>\n");
   p.indentRight();
   terminate.writeToStdOut(p);
   p.indentLeft();
   p.printf("</Termination>\n");
   p.printf("<Update>\n");
   p.indentRight();
   update.writeToStdOut(p);
   p.indentLeft();
   p.printf("</Update>\n");
   p.printf("<Consequent>\n");
   p.indentRight();
   block.writeToStdOut(p);
   p.indentLeft();
   p.printf("</Consequent>\n");
   p.indentLeft();
   p.printf("</JForStatement>\n");
 }
Пример #15
0
 private void printForUpdate(ForUpdate s, CodeWriter w, PrettyPrinter tr) {
   boolean oldSemiColon = tr.appendSemicolon(false);
   printBlock(s, w, tr);
   tr.appendSemicolon(oldSemiColon);
 }