/*
   * 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>"));
      }
    }
  }
示例#2
0
  /**
   * The main method.
   *
   * @param args the arguments
   */
  public static void main(String[] args) {

    final StringParameter PRM_BINDINGNAME =
        new StringParameter(
            "bindingName",
            "the name this server shall use to bind its remote reference in the RMI registry.");
    ;
    final BooleanParameter PRM_INITREGISTRY =
        new BooleanParameter(
            "initRegistry",
            "a boolean value, i.e. either true or false, indicating whether this server is responsible for creating the RMI registry or not.");
    final StringParameter PRM_SERVERNAMES =
        new StringParameter(
            "serverNames",
            "a list of names, separated by space characters, indicating the name of the other servers' remote references.");
    final CommandLineParser clp =
        new CommandLineParser("java server.Server", "Server for the lab2 event scheduling system.");
    clp.addParameters(PRM_BINDINGNAME, PRM_INITREGISTRY, PRM_SERVERNAMES);

    try {
      // Parse command line arguments
      clp.parse(args);

    } catch (ParseException pex) {
      logger.severe("Command parse error: " + pex.getMessage());
      System.out.println(clp.getUsageString());
      return;
    } catch (ValidationException vex) {
      logger.severe("Parameter validation error: " + vex.getMessage());
      System.out.println(clp.getUsageString());
      return;
    }

    RegistryInfo regInfo = null;
    try {
      regInfo = RegistryInfo.readRegistryInfo(PROPERTIES_FILE);
    } catch (ParseException pex) {
      logger.severe("Couldn't read properties file: " + pex.getMessage());
      return;
    } catch (FileNotFoundException fnfex) {
      logger.severe("The file \"" + PROPERTIES_FILE + "\" could not be found");
      return;
    } catch (IOException ioex) {
      logger.severe("Couldn't read properties file: " + ioex.getMessage());
      return;
    }

    Server srv =
        new Server(
            PRM_BINDINGNAME.getValue(),
            PRM_INITREGISTRY.getValue(),
            regInfo,
            PRM_SERVERNAMES.getValue().split("\\s"));

    if (!srv.start()) System.exit(1);

    try {
      new BufferedReader(new InputStreamReader(System.in)).readLine();
    } catch (IOException e) {
      logger.warning("Couldn't read from stdin");
    }

    try {
      srv.stop();
    } catch (Exception ex) {
      System.err.println("Error: " + ex.getMessage());
    }

    System.out.println("Shutting down..");
  }