/*
   * runs a sasl job using the given settings
   */
  public void run() {
    if (s.help()) {
      msg(s.getHelp());
      return;
    }

    msg(" - SASL Compiler 0.3 - \n\n");

    try {
      if (s.useSysIn()) {
        lexStream = System.in;
      }
      if (s.useFile()) {
        msg("Using " + s.filePath() + "\n");
        lexStream = new FileInputStream(s.filePath());
      }
      if (s.outputUseFile()) {
        outputStream = new PrintStream(new FileOutputStream(s.outputfilePath()));
      }

      if (s.useFile()) {
        msg("Lexing & Parsing " + s.filePath() + "... ");
      }
      if (s.useSysIn()) {
        msg("Code must be terminated by EOF (Unix:CTRL+D, Windows:CTRL+Z) \n");
        msg("\n[sasl]: ");
      }

      addIncludes();

      // lex
      Lexer lex = new Lexer(lexStream);
      // parse
      Node cTree = compile(parse(lex));

      // can be used to print the Tree to a dot file
      // DotPrinter dp = new DotPrinter(cTree);
      // System.out.println(dp.print());

      // reduce
      Node reduced = reduce(cTree);

      // print
      msg("\nResult:\n\n");
      Printer.print(outputStream, reduced);
      msg("\n\n");
      outputStream.close();
      stopTimer();
    } catch (ParseException e) {
      errorStream.println(e.getMessage());
    } catch (ReduceException e) {
      errorStream.println(e.getMessage());
    } catch (EOFException e) {
      errorStream.print("Error: Unexpected end of stream.");
    } catch (IOException e) {
      if (s.html()) {
        errorStream.print("Error IO: " + e.getMessage().replace("\n", "<br>"));
      }
    }
  }