Yylex.java
public static void main(String argv[]) {
    if (argv.length == 0) {
      System.out.println("Usage : java Yylex [ --encoding <name> ] <inputfile(s)>");
    }
    else {
      int firstFilePos = 0;
      String encodingName = "UTF-8";
      if (argv[0].equals("--encoding")) {
        firstFilePos = 2;
        encodingName = argv[1];
        try {
          java.nio.charset.Charset.forName(encodingName); // Side-effect: is encodingName valid? 
        } catch (Exception e) {
          System.out.println("Invalid encoding '" + encodingName + "'");
          return;
        }
      }
      for (int i = firstFilePos; i < argv.length; i++) {
        Yylex scanner = null;
        try {
          java.io.FileInputStream stream = new java.io.FileInputStream(argv[i]);
          java.io.Reader reader = new java.io.InputStreamReader(stream, encodingName);
          scanner = new Yylex(reader);
          while ( !scanner.zzAtEOF ) scanner.debug_next_token();
        }
        catch (java.io.FileNotFoundException e) {
          System.out.println("File not found : \""+argv[i]+"\"");
        }
        catch (java.io.IOException e) {
          System.out.println("IO error scanning file \""+argv[i]+"\"");
          System.out.println(e);
        }
        catch (Exception e) {
          System.out.println("Unexpected exception:");
          e.printStackTrace();
        }
      }
    }
  }
/**
   * Runs the scanner on input files.
   *
   * This main method is the debugging routine for the scanner.
   * It prints debugging information about each returned token to
   * System.out until the end of file is reached, or an error occured.
   *
   * @param argv   the command line, contains the filenames to run
   *               the scanner on.
   */
Runs the scanner on input files.
This main method is the debugging routine for the scanner.
It prints debugging information about each returned token to
System.out until the end of file is reached, or an error occured.

@param argv   the command line, contains the filenames to run
the scanner on.
Runs the scanner on input files . This main method is the debugging routine for the scanner . It prints debugging information about each returned token to System . out until the end of file is reached or an error occured . @param argv the command line contains the filenames to run the scanner on .
public static void main(String argv[]) {
    if (argv.length == 0) {
      System.out.println("Usage : java Yylex [ --encoding <name> ] <inputfile(s)>");
    }
    else {
      int firstFilePos = 0;
      String encodingName = "UTF-8";
      if (argv[0].equals("--encoding")) {
        firstFilePos = 2;
        encodingName = argv[1];
        try {
          java.nio.charset.Charset.forName(encodingName); 
        } catch (Exception e) {
          System.out.println("Invalid encoding '" + encodingName + "'");
          return;
        }
      }
      for (int i = firstFilePos; i < argv.length; i++) {
        Yylex scanner = null;
        try {
          java.io.FileInputStream stream = new java.io.FileInputStream(argv[i]);
          java.io.Reader reader = new java.io.InputStreamReader(stream, encodingName);
          scanner = new Yylex(reader);
          while ( !scanner.zzAtEOF ) scanner.debug_next_token();
        }
        catch (java.io.FileNotFoundException e) {
          System.out.println("File not found : \""+argv[i]+"\"");
        }
        catch (java.io.IOException e) {
          System.out.println("IO error scanning file \""+argv[i]+"\"");
          System.out.println(e);
        }
        catch (Exception e) {
          System.out.println("Unexpected exception:");
          e.printStackTrace();
        }
      }
    }
  }
public static void main ( String argv [ ] ) { if ( argv . length == 0 ) { System . out . println ( "Usage : java Yylex [ --encoding <name> ] <inputfile(s)>" ) ; } else { int firstFilePos = 0 ; String encodingName = "UTF-8" ; if ( argv [ 0 ] . equals ( "--encoding" ) ) { firstFilePos = 2 ; encodingName = argv [ 1 ] ; try { java . nio . charset . Charset . forName ( encodingName ) ; } catch ( Exception e ) { System . out . println ( "Invalid encoding '" + encodingName + "'" ) ; return ; } } for ( int i = firstFilePos ; i < argv . length ; i ++ ) { Yylex scanner = null ; try { java . io . FileInputStream stream = new java . io . FileInputStream ( argv [ i ] ) ; java . io . Reader reader = new java . io . InputStreamReader ( stream , encodingName ) ; scanner = new Yylex ( reader ) ; while ( ! scanner . zzAtEOF ) scanner . debug_next_token ( ) ; } catch ( java . io . FileNotFoundException e ) { System . out . println ( "File not found : \"" + argv [ i ] + "\"" ) ; } catch ( java . io . IOException e ) { System . out . println ( "IO error scanning file \"" + argv [ i ] + "\"" ) ; System . out . println ( e ) ; } catch ( Exception e ) { System . out . println ( "Unexpected exception:" ) ; e . printStackTrace ( ) ; } } } }
Runs the scanner on input files.
Runs the scanner on input files .
// Side-effect: is encodingName valid? 