Exemple #1
0
  /** test TokenManager */
  public static void main(String[] argv) {
    try {
      String dir = System.getProperty("user.dir");
      TokenManager tm =
          new VerilogTokenManager(
              new BufferedReader(new FileReader(dir + "\\ac97_top.v")), false, null);
      Token token = null;
      int kind = tm.getNextTokenKind();
      kind = tm.getNextTokenKind(2);
      kind = tm.getNextTokenKind(5);
      // MyDebug.printFileLine(kind);

      int lastLine = 0x0fffffff;
      while (true) {
        token = tm.toNextToken();
        if (token == null) {
          break;
        }
        if (lastLine < token.beginLine) {
          MyDebug.printFileLine();
        }
        MyDebug.printFileLine(" " + token.image);
        lastLine = token.endLine;
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ParserException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public static void main(String[] args) throws LexerException, IOException, ParserException {
    String input = "";
    String fileName = "";
    if (args.length < 2) { // catch valid number of arguments
      System.out.println(
          "# Error: Not enough arguments.\n# Usage: > java StupsCompiler -argument <Filename.pas>\n# Valid arguments are: -compile, -liveness.");
      System.exit(1);
    }
    if (!args[1].endsWith(".pas")) { // catch valid file extension
      System.out.println("# Error: Valid file extension is only '.pas'.");
      System.exit(1);
    } else {
      fileName = args[1];
    }
    try {
      String zeile;
      fileName = args[1];
      FileReader fr = new FileReader(fileName);
      BufferedReader br = new BufferedReader(fr);

      zeile = br.readLine();
      while (zeile != null) {
        input += zeile + "\n";
        zeile = br.readLine();
      }
      br.close();

      if (args[0].equals("-compile")) { // Compile section
        parseCompile(input, fileName.substring(0, fileName.lastIndexOf('.')));

      } else if (args[0].equals("-liveness")) {
        parseLiveness(input);
      } else {
        System.out.println(
            "# Error: Wrong usage of StupsCompiler.\n# Usage: > java StupsCompiler -compile <Filename.pas>");
      }
    } catch (FileNotFoundException e) {
      System.out.println(
          "# Error: File '" + fileName + "' not found. Please enter correct filename.");
    } catch (ParserException e) {
      System.out.println("# Error in " + fileName + ": " + e.getMessage() + "\n#");
      printErrorLine(e.getMessage(), input);
    } catch (LexerException e) {
      System.out.println("# Error in " + fileName + ": " + e.getMessage() + "\n#");
      printErrorLine(e.getMessage(), input);
    }
  }