/* Generated By:JavaCC: Do not edit this line. ConfigFile.java */
package org.dacapo.parser;

import com.jingpu.android.apersistance.util.TPCCLog;

import java.io.*;
import java.util.Vector;
import java.util.ArrayList;

class ConfigFile implements ConfigFileConstants {
  public static void main(String[] args) {
    ConfigFile parser;
    try {
      parser = new ConfigFile(new FileInputStream(args[0]));
      parser.configFile();
    } catch (ParseException p) {
      TPCCLog.e(ConfigFile.class.getName(), "Parse exception");
        p.printStackTrace();
        return;
    } catch (FileNotFoundException e) {
      TPCCLog.e(ConfigFile.class.getName(), "File " + args[0] + " not found.");
        return;
    }
    TPCCLog.v(ConfigFile.class.getName(), "Success!");
  }

  private static String unQuote(Token token) {
        return token.image.substring(1,token.image.length()-1);
  }

  private static String unHex(Token token) {
        return token.image.substring(2).toLowerCase();
  }

  final public Config configFile() throws ParseException {
  Config config;
    config = config();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case SIZE:
        sizeSpec(config);
        break;
      case DESCRIPTION:
        description(config);
        break;
      default:
        jj_la1[0] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DESCRIPTION:
      case SIZE:
        ;
        break;
      default:
        jj_la1[1] = jj_gen;
        break label_1;
      }
    }
    {if (true) return config;}
    throw new Error("Missing return statement in function");
  }

  final public Config config() throws ParseException {
  Config config; Token name;
    jj_consume_token(BENCHMARK);
    name = jj_consume_token(IDENT);
    config = new Config(name.image);
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case CLASS:
      case JAR:
      case LIBS:
      case THREAD_MODEL:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_2;
      }
      configOption(config);
    }
    jj_consume_token(SEMI);
    {if (true) return config;}
    throw new Error("Missing return statement in function");
  }

  final public void configOption(Config config) throws ParseException {
  String className; Config.ThreadModel threadModel; String jar;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case CLASS:
      jj_consume_token(CLASS);
      className = identifier();
                                     config.setClass(className);
      break;
    case THREAD_MODEL:
      jj_consume_token(THREAD_MODEL);
      threadModel = threadModel();
                                               config.setThreadModel(threadModel);
      break;
    case JAR:
      jj_consume_token(JAR);
      jar = string();
                         config.setJar(jar);
      break;
    case LIBS:
      jj_consume_token(LIBS);
      libraries(config);
      break;
    default:
      jj_la1[3] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void libraries(Config config) throws ParseException {
  ArrayList libs = new ArrayList(); String lib;
    lib = string();
                 libs.add(lib);
    label_3:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case COMMA:
        ;
        break;
      default:
        jj_la1[4] = jj_gen;
        break label_3;
      }
      jj_consume_token(COMMA);
      lib = string();
                                                          libs.add(lib);
    }
    config.setLibs((String[]) libs.toArray(new String[0]));
  }

  final public void sizeSpec(Config config) throws ParseException {
  Token size;
    jj_consume_token(SIZE);
    size = jj_consume_token(IDENT);
    label_4:
    while (true) {
      sizeClause(config,size.image);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case ARGS:
      case DESCRIPTION:
      case OUTPUT:
      case THREADS:
      case THREAD_LIMIT:
        ;
        break;
      default:
        jj_la1[5] = jj_gen;
        break label_4;
      }
    }
    jj_consume_token(SEMI);
  }

  final public void sizeClause(Config config, String size) throws ParseException {
    Vector args = new Vector();
  String arg;
  String description;
  int thread_limit;
  int threads;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case ARGS:
      jj_consume_token(ARGS);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case STRING_LITERAL:
        arg = string();
                            args.add(arg);
        label_5:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case COMMA:
            ;
            break;
          default:
            jj_la1[6] = jj_gen;
            break label_5;
          }
          jj_consume_token(COMMA);
          arg = string();
                                    args.add(arg);
        }
        break;
      default:
        jj_la1[7] = jj_gen;
        ;
      }
         config.addSize(size,args);
      break;
    case DESCRIPTION:
      jj_consume_token(DESCRIPTION);
      description = string();
                                            config.setSizeDescription(size,description);
      break;
    case THREAD_LIMIT:
      jj_consume_token(THREAD_LIMIT);
      thread_limit = integer();
                                               config.setThreadLimit(size,thread_limit);
      break;
    case THREADS:
      jj_consume_token(THREADS);
      threads = integer();
                                     config.setThreadFactor(size,threads);
      break;
    case OUTPUT:
      jj_consume_token(OUTPUT);
      outputFile(config,size);
      label_6:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case COMMA:
          ;
          break;
        default:
          jj_la1[8] = jj_gen;
          break label_6;
        }
        jj_consume_token(COMMA);
        outputFile(config,size);
      }
      break;
    default:
      jj_la1[9] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void outputFile(Config config, String size) throws ParseException {
  String file;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case STRING_LITERAL:
      file = string();
      break;
    case STDOUT:
      jj_consume_token(STDOUT);
               file = "stdout.log";
      break;
    case STDERR:
      jj_consume_token(STDERR);
               file = "stderr.log";
      break;
    default:
      jj_la1[10] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    config.addOutputFile(size,file);
    label_7:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case BYTES:
      case DIGEST:
      case EXISTS:
      case KEEP:
      case LINES:
        ;
        break;
      default:
        jj_la1[11] = jj_gen;
        break label_7;
      }
      outputClause(config,size,file);
    }
  }

  final public void outputClause(Config config, String size, String file) throws ParseException {
  String digest; int n; long l;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case DIGEST:
      jj_consume_token(DIGEST);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case LPAREN:
        jj_consume_token(LPAREN);
        digestOption(config,size,file);
        label_8:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case COMMA:
            ;
            break;
          default:
            jj_la1[12] = jj_gen;
            break label_8;
          }
          jj_consume_token(COMMA);
          digestOption(config,size,file);
        }
        jj_consume_token(RPAREN);
        break;
      default:
        jj_la1[13] = jj_gen;
        ;
      }
      digest = hex();
                   config.setDigest(size,file,digest);
      break;
    case EXISTS:
      jj_consume_token(EXISTS);
                            config.setExists(size,file);
      break;
    case KEEP:
      jj_consume_token(KEEP);
                            config.setKeep(size,file);
      break;
    case LINES:
      jj_consume_token(LINES);
      n = integer();
                            config.setLines(size,file,n);
      break;
    case BYTES:
      jj_consume_token(BYTES);
      l = longInt();
                            config.setBytes(size,file,l);
      break;
    default:
      jj_la1[14] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void digestOption(Config config, String size, String file) throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case TEXT:
      jj_consume_token(TEXT);
                  config.setTextFile(size,file,true);
      break;
    case BINARY:
      jj_consume_token(BINARY);
                   config.setTextFile(size,file,false);
      break;
    case FILTER:
      jj_consume_token(FILTER);
                   config.setFilterScratch(size,file,true);
      break;
    case RAW:
      jj_consume_token(RAW);
                  config.setFilterScratch(size,file,false);
      break;
    default:
      jj_la1[15] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public Config.ThreadModel threadModel() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case SINGLE:
      jj_consume_token(SINGLE);
               {if (true) return Config.ThreadModel.SINGLE;}
      break;
    case FIXED:
      jj_consume_token(FIXED);
               {if (true) return Config.ThreadModel.FIXED;}
      break;
    case PER_CPU:
      jj_consume_token(PER_CPU);
                {if (true) return Config.ThreadModel.PER_CPU;}
      break;
    default:
      jj_la1[16] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    throw new Error("Missing return statement in function");
  }

  final public void description(Config config) throws ParseException {
    jj_consume_token(DESCRIPTION);
    descElement(config);
    label_9:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case COMMA:
        ;
        break;
      default:
        jj_la1[17] = jj_gen;
        break label_9;
      }
      jj_consume_token(COMMA);
      descElement(config);
    }
    jj_consume_token(SEMI);
  }

  final public void descElement(Config config) throws ParseException {
  String id, desc;
    id = descId();
    desc = string();
    config.addDesc(id,desc);
  }

  final public String descId() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case AUTHOR:
      jj_consume_token(AUTHOR);
      break;
    case COPYRIGHT:
      jj_consume_token(COPYRIGHT);
      break;
    case LICENSE:
      jj_consume_token(LICENSE);
      break;
    case LONG:
      jj_consume_token(LONG);
      break;
    case SHORT:
      jj_consume_token(SHORT);
      break;
    case THREADS:
      jj_consume_token(THREADS);
      break;
    case REPEATS:
      jj_consume_token(REPEATS);
      break;
    case URL:
      jj_consume_token(URL);
      break;
    case VERSION:
      jj_consume_token(VERSION);
      break;
    default:
      jj_la1[18] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    {if (true) return token.image;}
    throw new Error("Missing return statement in function");
  }

  final public String identifier() throws ParseException {
    jj_consume_token(IDENT);
            {if (true) return token.image;}
    throw new Error("Missing return statement in function");
  }

  final public String string() throws ParseException {
    jj_consume_token(STRING_LITERAL);
                     {if (true) return unQuote(token);}
    throw new Error("Missing return statement in function");
  }

  final public int integer() throws ParseException {
    jj_consume_token(INT_LITERAL);
                  {if (true) return Integer.parseInt(token.image);}
    throw new Error("Missing return statement in function");
  }

  final public long longInt() throws ParseException {
    jj_consume_token(INT_LITERAL);
                  {if (true) return Long.parseLong(token.image);}
    throw new Error("Missing return statement in function");
  }

  final public String hex() throws ParseException {
    jj_consume_token(HEX_STRING);
                 {if (true) return unHex(token);}
    throw new Error("Missing return statement in function");
  }

  /** Generated Token Manager. */
  public ConfigFileTokenManager token_source;
  SimpleCharStream jj_input_stream;
  /** Current token. */
  public Token token;
  /** Next token. */
  public Token jj_nt;
  private int jj_ntk;
  private int jj_gen;
  final private int[] jj_la1 = new int[19];
  static private int[] jj_la1_0;
  static private int[] jj_la1_1;
  static {
      jj_la1_init_0();
      jj_la1_init_1();
   }
   private static void jj_la1_init_0() {
      jj_la1_0 = new int[] {0x100000,0x100000,0xa040000,0xa040000,0x0,0x102000,0x0,0x0,0x0,0x102000,0x0,0x24620000,0x0,0x0,0x24620000,0x810000,0x1000000,0x0,0x50084000,};
   }
   private static void jj_la1_init_1() {
      jj_la1_1 = new int[] {0x20,0x20,0x2000,0x2000,0x80000,0x1801,0x80000,0x20000,0x80000,0x1801,0x200c0,0x0,0x80000,0x100000,0x0,0x104,0x12,0x80000,0x4e08,};
   }

  /** Constructor with InputStream. */
  public ConfigFile(InputStream stream) {
     this(stream, null);
  }
  /** Constructor with InputStream and supplied encoding */
  public ConfigFile(InputStream stream, String encoding) {
    try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); }
    token_source = new ConfigFileTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 19; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  public void ReInit(InputStream stream) {
     ReInit(stream, null);
  }
  /** Reinitialise. */
  public void ReInit(InputStream stream, String encoding) {
    try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); }
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 19; i++) jj_la1[i] = -1;
  }

  /** Constructor. */
  public ConfigFile(Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new ConfigFileTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 19; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  public void ReInit(Reader stream) {
    jj_input_stream.ReInit(stream, 1, 1);
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 19; i++) jj_la1[i] = -1;
  }

  /** Constructor with generated Token Manager. */
  public ConfigFile(ConfigFileTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 19; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  public void ReInit(ConfigFileTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 19; i++) jj_la1[i] = -1;
  }

  private Token jj_consume_token(int kind) throws ParseException {
    Token oldToken;
    if ((oldToken = token).next != null) token = token.next;
    else token = token.next = token_source.getNextToken();
    jj_ntk = -1;
    if (token.kind == kind) {
      jj_gen++;
      return token;
    }
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  }


/** Get the next Token. */
  final public Token getNextToken() {
    if (token.next != null) token = token.next;
    else token = token.next = token_source.getNextToken();
    jj_ntk = -1;
    jj_gen++;
    return token;
  }

/** Get the specific Token. */
  final public Token getToken(int index) {
    Token t = token;
    for (int i = 0; i < index; i++) {
      if (t.next != null) t = t.next;
      else t = t.next = token_source.getNextToken();
    }
    return t;
  }

  private int jj_ntk() {
    if ((jj_nt=token.next) == null)
      return (jj_ntk = (token.next=token_source.getNextToken()).kind);
    else
      return (jj_ntk = jj_nt.kind);
  }

  private java.util.List jj_expentries = new ArrayList();
  private int[] jj_expentry;
  private int jj_kind = -1;

  /** Generate ParseException. */
  public ParseException generateParseException() {
    jj_expentries.clear();
    boolean[] la1tokens = new boolean[55];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 19; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<<j)) != 0) {
            la1tokens[j] = true;
          }
          if ((jj_la1_1[i] & (1<<j)) != 0) {
            la1tokens[32+j] = true;
          }
        }
      }
    }
    for (int i = 0; i < 55; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.add(jj_expentry);
      }
    }
    int[][] exptokseq = new int[jj_expentries.size()][];
    for (int i = 0; i < jj_expentries.size(); i++) {
      exptokseq[i] = (int[])jj_expentries.get(i);
    }
    return new ParseException(token, exptokseq, tokenImage);
  }

  /** Enable tracing. */
  final public void enable_tracing() {
  }

  /** Disable tracing. */
  final public void disable_tracing() {
  }

}
