Package xtc.tree

Examples of xtc.tree.Printer


     
     
      //write type checker file
      File    dir  = runtime.getFile(Runtime.OUTPUT_DIRECTORY);
      File    file = new File(dir, output + "Analyzer.java" );
      Printer out;
      // Write the xxxAnalyzer.java file
      if (!runtime.test("optionTypesOnly")) {
        try {     
          out = new
            Printer(new PrintWriter(new BufferedWriter(new FileWriter(file))));
        } catch (IOException x) {
          if (null == x.getMessage()) {
            runtime.error(file.toString() + ": I/O error");
          } else {
            runtime.error(file.toString() + ": " + x.getMessage());
          }
          return;
        }     
        printHeader(out);
        new JavaPrinter(out).dispatch(result_ast);
        out.flush();
      }

      // Write the xxxTypes.java
      file = new File(dir, output + "Types.java" );
      try {     
        out = new
          Printer(new PrintWriter(new BufferedWriter(new FileWriter(file))));
      } catch (IOException x) {
        if (null == x.getMessage()) {
          runtime.error(file.toString() + ": I/O error");
        } else {
          runtime.error(file.toString() + ": " + x.getMessage());
        }
        return;
      }     
      printHeader(out);
      new JavaPrinter(out).dispatch(types_ast);
      out.flush();
     
      // Write the xxxSupport.java
      file = new File(dir, output + "Support.java" );
      try {     
        out = new
          Printer(new PrintWriter(new BufferedWriter(new FileWriter(file))));
      } catch (IOException x) {
        if (null == x.getMessage()) {
          runtime.error(file.toString() + ": I/O error");
        } else {
          runtime.error(file.toString() + ": " + x.getMessage());
        }
        return;
      }     
      printHeader(out);
      new JavaPrinter(out).dispatch(support_ast);
      out.flush();
    }

    if (runtime.test("printSource")) {
      new JavaPrinter(runtime.console()).dispatch(result_ast);
      runtime.console().flush();
View Full Code Here


    // Process the productions.
    for (Production p : m.productions) analyzer.process(p);

    // Print the header.
    final Printer printer = runtime.console();

    printer.sep();
    printer.indent().p("// Generated by Rats!, version ").p(Constants.VERSION).
      p(", ").p(Constants.COPY).pln('.');
    printer.sep();
    printer.pln();

    printer.indent().p("/** AST structure for grammar ").p(m.name.name).
      pln(". */");

    // Ensure that all tuples are concrete and then print the result.
    if (! runtime.test("optionVariant")) {
      // Flat AST definition.
      final VariantT node = ast.toVariant("Node", false);

      ast.concretizeTuples(node, UnitT.TYPE);
      printer.indent().p("module ").p(m.name.name).p("Tree").pln(';');
      printer.pln();
      ast.print(node, printer, true, false, null);
      printer.pln();

    } else {
      // Hierarchical AST definition.
      final VariantT     root      =
        analyzer.lookup((NonTerminal)m.getProperty(Properties.ROOT)).
        type.resolve().toVariant();
      final AST.MetaData meta      = ast.getMetaData(root);
      final Set<String>  processed = new HashSet<String>();

      // Concretize variants.
      for (Production p : m.productions) {
        if (AST.isStaticNode(p.type)) {
          final VariantT variant = p.type.resolve().toVariant();
          final String   name    = variant.getName();

          if (meta.reachable.contains(name) && ! processed.contains(name)) {
            processed.add(name);
            ast.concretizeTuples(variant, UnitT.TYPE);
          }
        }
      }
      processed.clear();

      // Print variants...
      if (! meta.modularize) {
        // ... in a single module.
        printer.indent().p("module ").p(m.name.name).p("Tree").pln(';');
        printer.pln();

        for (Production p : m.productions) {
          if (AST.isStaticNode(p.type)) {
            final VariantT variant = p.type.resolve().toVariant();
            final String   name    = variant.getName();
           
            if (meta.reachable.contains(name) && ! processed.contains(name)) {
              processed.add(name);
              ast.print(variant, printer, true, false, null);
              printer.pln();
            }
          }
        }

      } else {
        // ... across several modules.
        boolean first = true;
        String  module;

        do {
          module = null;

          for (Production p : m.productions) {
            if (AST.isStaticNode(p.type)) {
              final VariantT variant = p.type.resolve().toVariant();
              final String   name    = variant.getName();

              if (meta.reachable.contains(name) && ! processed.contains(name)) {
                final String qualifier = variant.getQualifier();
               
                if (null == module) {
                  module = qualifier;
                 
                  if (first) {
                    first = false;
                  } else {
                    printer.sep().pln();
                  }
                  printer.indent().p("module ").p(module).pln(';');
                  printer.pln();
                 
                } else if (! module.equals(qualifier)) {
                  continue;
                }
               
                processed.add(name);
                ast.print(variant, printer, true, true, module);
                printer.pln();
              }
            }
          }
        } while (null != module);
      }
    }

    printer.sep().flush();
  }
View Full Code Here

   *
   * @param name The file name.
   */
  protected void open(String name) throws IOException {
    File file = new File(runtime.getOutputDirectory(), name);
    printer   = new Printer(new PrintWriter(runtime.getWriter(file)));
  }
View Full Code Here

   * Create a new runtime.  Note that the list of input directories is
   * empty, while the output directory is initialized to the current
   * directory.
   */
  public Runtime() {
    console     = new
      Printer(new BufferedWriter(new OutputStreamWriter(System.out)));
    errConsole  = new
      Printer(new BufferedWriter(new OutputStreamWriter(System.err)));
    optionList  = new ArrayList<Option>();
    externalMap = new HashMap<String, Option>();
    internalMap = new HashMap<String, Option>();
    options     = new HashMap<String, Object>();
View Full Code Here

  /** Hide the constructor. */
  private Platform() { /* Nothing to do. */ }

  /** Generate the current platform's configuration header. */
  public static void main(String[] args) {
    Printer printer = new
      Printer(new BufferedWriter(new OutputStreamWriter(System.out)));

    printer.p("#define OS \"").p(System.getProperty("os.name")).p(' ').
      p(System.getProperty("os.version")).pln('"');
    printer.p("#define ARCH \"").p(System.getProperty("os.arch")).pln('"');
    printer.flush();
  }
View Full Code Here

    //                        Generate parser
    // --------------------------------------------------------------------
   
    File file = new File(runtime.getOutputDirectory(),
                         Utilities.getName(module.getClassName()) + ".java");
    Printer out;
    try {
      out = new Printer(new PrintWriter(runtime.getWriter(file)));
    } catch (IOException x) {
      if (null == x.getMessage()) {
        runtime.error(file.toString() + ": I/O error");
      } else {
        runtime.error(file.toString() + ": " + x.getMessage());
      }
      return;
    }
    printHeader(out);
    new CodeGenerator(runtime, ana, ast, out).dispatch(module);
    out.flush().close();
  }
View Full Code Here

TOP

Related Classes of xtc.tree.Printer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.