/* Generated By:JavaCC: Do not edit this line. EQLParserGenericImpl.java */
package com.queplix.core.modules.eql.parser.generic.jj;

import java.util.*;
import java.io.*;

import com.queplix.core.modules.eql.*;
import com.queplix.core.modules.eql.error.*;
import com.queplix.core.modules.eql.conds.*;
import com.queplix.core.modules.eql.ops.*;
import com.queplix.core.modules.eql.parser.*;
import com.queplix.core.modules.eql.parser.generic.*;
import com.queplix.core.modules.eql.utils.*;

public class EQLParserGenericImpl extends AbstractEQLParser implements EQLParserGenericImplConstants {

  private EQLIntMediator mediator;
  private String eql;

  public EQLParserGenericImpl( EQLIntMediator mediator, String eql ) {
    this( new CharArrayReader(eql.toCharArray()) );
    this.mediator = mediator;
    this.eql = eql;
  }

  public void parse()
    throws EQLException {

    try {
      process( mediator );
    } catch (ParseException ex) {
      printError( ex.getMessage() );
      throw new EQLParseException( eql );
    }
  }

  public EQLReqOp parseSrc()
    throws EQLException {

    try {
      return op_attr( mediator );
    } catch (ParseException ex) {
      printError( ex.getMessage() );
      throw new EQLParseException( eql );
    }
  }

  public void parseWhere()
    throws EQLException {

    try {
      where_attr( mediator );
    } catch (ParseException ex) {
      printError( ex.getMessage() );
      throw new EQLParseException( eql );
    }
  }

  public void parseOrder()
    throws EQLException {

    try {
      order_attr( mediator, false );
    } catch (ParseException ex) {
      printError( ex.getMessage() );
      throw new EQLParseException( eql );
    }
  }

  public EQLIntMediator getMediator() {
    return mediator;
  }

//
// main process
//
  final public void process(EQLIntMediator mediator) throws ParseException, EQLException {
        Token t;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case SELECT:
      jj_consume_token(SELECT);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 41:
        jj_consume_token(41);
        meta_attr(mediator);
        jj_consume_token(42);
        break;
      default:
        jj_la1[0] = jj_gen;
        ;
      }
      select_attr(mediator);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case WHERE:
        jj_consume_token(WHERE);
        where_attr(mediator);
        break;
      default:
        jj_la1[1] = jj_gen;
        ;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case ORDER:
        jj_consume_token(ORDER);
        jj_consume_token(BY);
        order_attr(mediator,true);
        break;
      default:
        jj_la1[2] = jj_gen;
        ;
      }
      break;
    case AGGREGATE:
      jj_consume_token(AGGREGATE);
      aggregate_func(mediator);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case WHERE:
        jj_consume_token(WHERE);
        where_attr(mediator);
        break;
      default:
        jj_la1[3] = jj_gen;
        ;
      }
      break;
    case NEW:
      jj_consume_token(NEW);
      t = jj_consume_token(ID);
      // select field default value
      mediator.addSelectColumnAsDefault( getReqFieldByFieldId(t.image) );
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 43:
        jj_consume_token(43);
        break;
      default:
        jj_la1[4] = jj_gen;
        ;
      }
      break;
    default:
      jj_la1[5] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

//
// begin parse query meta information
//
  final public void meta_attr(EQLIntMediator mediator) throws ParseException, EQLException {
        Token t1;
        Token t2;
    t1 = jj_consume_token(ID);
    jj_consume_token(EQ);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case TRUE:
      t2 = jj_consume_token(TRUE);
                  mediator.addMetaInfoAsBoolean(t1.image, Boolean.TRUE);
      break;
    case FALSE:
      t2 = jj_consume_token(FALSE);
                   mediator.addMetaInfoAsBoolean(t1.image, Boolean.FALSE);
      break;
    case NUMBER:
      t2 = jj_consume_token(NUMBER);
                    mediator.addMetaInfoAsNumber(t1.image, t2.image);
      break;
    case LIST:
      t2 = jj_consume_token(LIST);
                  mediator.addMetaInfoAsList(t1.image, t2.image);
      break;
    default:
      jj_la1[6] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 44:
      jj_consume_token(44);
      break;
    default:
      jj_la1[7] = jj_gen;
      ;
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case ID:
      meta_attr(mediator);
      break;
    default:
      jj_la1[8] = jj_gen;
      ;
    }
  }

//
// begin parse select_clause
//
  final public void select_attr(EQLIntMediator mediator) throws ParseException, EQLException {
        Token t;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case SELECT_ALL_COLUMNS:
      t = jj_consume_token(SELECT_ALL_COLUMNS);
    // select all columns: "select entity.*"
    mediator.addSelectAllColumns( getTopLevelEntity(t.image) );
      break;
    case ID:
      t = jj_consume_token(ID);
    // select one column: "select entity.field"
    mediator.addSelectColumn( getReqFieldByFieldId(t.image) );
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 44:
        jj_consume_token(44);
        select_attr(mediator);
        break;
      default:
        jj_la1[9] = jj_gen;
        ;
      }
      break;
    default:
      jj_la1[11] = jj_gen;
        aggregate_func( mediator );
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 44:
        jj_consume_token(44);
        select_attr(mediator);
        break;
      default:
        jj_la1[10] = jj_gen;
        ;
      }
    }
  }

//
// begin parse where_clause
//
  final public void where_attr(EQLIntMediator mediator) throws ParseException, EQLException {
    where_attr1(mediator, mediator.getEQLReq().getWhere(), EQLReqSubWhere.NONE_OP);
  }

//
// [(] where_clause [)]
//
  final public void where_attr1(EQLIntMediator mediator, EQLReqWhere parent, int where_op) throws ParseException, EQLException {
    if (jj_2_1(2147483647)) {
      where_attr2(mediator, parent, where_op);
    } else {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case NULL:
      case PARAM:
      case NUMBER:
      case STRING:
      case ID:
      case LISTID:
      case FUNCTION:
      case 45:
        where_attr3(mediator, parent, where_op);
        break;
      default:
        jj_la1[12] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case AND:
    case OR:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case AND:
        jj_consume_token(AND);
              where_op = EQLReqSubWhere.AND_OP;
        break;
      case OR:
        jj_consume_token(OR);
             where_op = EQLReqSubWhere.OR_OP;
        break;
      default:
        jj_la1[13] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      where_attr1(mediator, parent, where_op);
      break;
    default:
      jj_la1[14] = jj_gen;
      ;
    }
  }

//
// ( where_clause )
//
  final public void where_attr2(EQLIntMediator mediator, EQLReqWhere parent, int where_op) throws ParseException, EQLException {
  EQLReqWhere next;
    jj_consume_token(45);
      next = mediator.addSubWhere( parent, where_op );
    where_attr1(mediator, next, EQLReqSubWhere.NONE_OP);
    jj_consume_token(46);
  }

//
// where_clause
//
  final public void where_attr3(EQLIntMediator mediator, EQLReqWhere parent, int where_op) throws ParseException, EQLException {
  EQLReqSubWhereCond subWhereCond = null;
  EQLReqOp leftMember;
  EQLReqOp rightMember;
    leftMember = op_attr(mediator);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case IS:
    case IN:
    case NOT:
    case EQ:
    case NE:
    case GT:
    case LT:
    case GTEQ:
    case LTEQ:
    case LIKE:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IN:
      case NOT:
      case EQ:
      case NE:
      case GT:
      case LT:
      case GTEQ:
      case LTEQ:
      case LIKE:
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case GTEQ:
          jj_consume_token(GTEQ);
          rightMember = op_attr(mediator);
          subWhereCond = new GtEqCond(leftMember,rightMember);
          break;
        case LTEQ:
          jj_consume_token(LTEQ);
          rightMember = op_attr(mediator);
          subWhereCond = new LtEqCond(leftMember,rightMember);
          break;
        case NE:
          jj_consume_token(NE);
          rightMember = op_attr(mediator);
          subWhereCond = new NotEqCond(leftMember,rightMember);
          break;
        case EQ:
          jj_consume_token(EQ);
          rightMember = op_attr(mediator);
          subWhereCond = new EqCond(leftMember,rightMember);
          break;
        case GT:
          jj_consume_token(GT);
          rightMember = op_attr(mediator);
          subWhereCond = new GtCond(leftMember,rightMember);
          break;
        case LT:
          jj_consume_token(LT);
          rightMember = op_attr(mediator);
          subWhereCond = new LtCond(leftMember,rightMember);
          break;
        case LIKE:
          jj_consume_token(LIKE);
          rightMember = op_attr(mediator);
          subWhereCond = new LikeCond(leftMember,rightMember);
          break;
        case IN:
          jj_consume_token(IN);
          rightMember = in_op_attr(mediator);
          subWhereCond = new InCond(leftMember,rightMember);
          break;
        case NOT:
          if (jj_2_2(2)) {
            jj_consume_token(NOT);
            jj_consume_token(LIKE);
            rightMember = op_attr(mediator);
            subWhereCond = new NotLikeCond(leftMember,rightMember);
          } else {
            switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
            case NOT:
              jj_consume_token(NOT);
              jj_consume_token(IN);
              rightMember = in_op_attr(mediator);
            subWhereCond = new NotInCond(leftMember,rightMember);
              break;
            default:
              jj_la1[15] = jj_gen;
              jj_consume_token(-1);
              throw new ParseException();
            }
          }
          break;
        default:
          jj_la1[16] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
        break;
      case IS:
        if (jj_2_3(2)) {
          jj_consume_token(IS);
          jj_consume_token(NULL);
        subWhereCond = new IsNullCond(leftMember);
        } else {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case IS:
            jj_consume_token(IS);
            jj_consume_token(NOT);
            jj_consume_token(NULL);
        subWhereCond = new IsNotNullCond(leftMember);
            break;
          default:
            jj_la1[17] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
          }
        }
        break;
      default:
        jj_la1[18] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      break;
    default:
      jj_la1[19] = jj_gen;
      ;
    }
    mediator.addSubWhereCondition( parent, where_op, (subWhereCond == null) ? new NoneCond(leftMember) : subWhereCond );
  }

//
// order_clause
//
  final public void order_attr(EQLIntMediator mediator, boolean mandatory) throws ParseException, EQLException {
  Token t;
  int order_op = EQLReqSubOrder.ASC_OP;
    t = jj_consume_token(ID);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case ASC:
    case DESC:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case ASC:
        jj_consume_token(ASC);
            order_op = EQLReqSubOrder.ASC_OP;
        break;
      case DESC:
        jj_consume_token(DESC);
             order_op = EQLReqSubOrder.DESC_OP;
        break;
      default:
        jj_la1[20] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      break;
    default:
      jj_la1[21] = jj_gen;
      ;
    }
    mediator.addSubOrder( getReqFieldByFieldId(t.image), order_op, mandatory );
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 44:
      jj_consume_token(44);
      order_attr(mediator,mandatory);
      break;
    default:
      jj_la1[22] = jj_gen;
      ;
    }
  }

//***********
// OPERATION
//***********

//
// begin operation
//
  final public EQLReqOp op_attr(EQLIntMediator mediator) throws ParseException, EQLException {
  EQLReqOp parent = new EQLReqOp();
  EQLReqSubOpMember subOpMember;
    subOpMember = op_attr1(mediator, parent);
    mediator.addSubOp( new NoneOp(subOpMember), parent );
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case PLUS:
    case MINUS:
    case DIV:
    case MULT:
      op_attr2(mediator,parent);
      break;
    default:
      jj_la1[23] = jj_gen;
      ;
    }
    {if (true) return parent;}
    throw new Error("Missing return statement in function");
  }

//
// [(] operation [)]
//
  final public EQLReqSubOpMember op_attr1(EQLIntMediator mediator, EQLReqOp parent) throws ParseException, EQLException {
  EQLReqSubOpMember subOpMember;
    if (jj_2_4(2)) {
      subOpMember = op_attr3(mediator);
    } else {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 45:
        subOpMember = op_attr4(mediator);
        break;
      default:
        jj_la1[24] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    {if (true) return subOpMember;}
    throw new Error("Missing return statement in function");
  }

//
// {+|-|...) operation
//
  final public void op_attr2(EQLIntMediator mediator, EQLReqOp parent) throws ParseException, EQLException {
  EQLReqSubOpMember subOpMember;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case PLUS:
      jj_consume_token(PLUS);
      subOpMember = op_attr1(mediator,parent);
      mediator.addSubOp(new PlusOp(subOpMember),parent);
      break;
    case MINUS:
      jj_consume_token(MINUS);
      subOpMember = op_attr1(mediator,parent);
      mediator.addSubOp(new MinusOp(subOpMember),parent);
      break;
    case DIV:
      jj_consume_token(DIV);
      subOpMember = op_attr1(mediator,parent);
      mediator.addSubOp(new DivOp(subOpMember),parent);
      break;
    case MULT:
      jj_consume_token(MULT);
      subOpMember = op_attr1(mediator,parent);
      mediator.addSubOp(new MultOp(subOpMember),parent);
      break;
    default:
      jj_la1[25] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case PLUS:
    case MINUS:
    case DIV:
    case MULT:
      op_attr2(mediator,parent);
      break;
    default:
      jj_la1[26] = jj_gen;
      ;
    }
  }

//
// operation
//
  final public EQLReqSubOpMember op_attr3(EQLIntMediator mediator) throws ParseException, EQLException {
  Token t;
  EQLReqSubOpMember subOpMember;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case PARAM:
      t = jj_consume_token(PARAM);
      subOpMember = mediator.buildNextSubOperation();
      break;
    case ID:
      t = jj_consume_token(ID);
      subOpMember = mediator.buildSubOperationMemberField( getReqFieldByFieldId(t.image) );
      break;
    case LISTID:
      t = jj_consume_token(LISTID);
      subOpMember = mediator.buildSubOperationMemberListField( getReqFieldByFieldId(t.image.substring(1)) );
      break;
    case NULL:
    case NUMBER:
    case STRING:
      subOpMember = constants(mediator);
      break;
    case FUNCTION:
      subOpMember = function(mediator);
      break;
    case 45:
      subOpMember = subquery(mediator);
      break;
    default:
      jj_la1[27] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    {if (true) return subOpMember;}
    throw new Error("Missing return statement in function");
  }

//
// ( operation )
//
  final public EQLReqSubOpMember op_attr4(EQLIntMediator mediator) throws ParseException, EQLException {
  EQLReqOp next;
    jj_consume_token(45);
    next = op_attr(mediator);
    jj_consume_token(46);
    {if (true) return next;}
    throw new Error("Missing return statement in function");
  }

//
// constants
//
  final public EQLObject constants(EQLIntMediator mediator) throws ParseException, EQLException {
  Token t;
  EQLObject subOpMember;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case NUMBER:
      t = jj_consume_token(NUMBER);
      subOpMember = mediator.buildSubOperationMemberNumber( t.image );
      break;
    case STRING:
      t = jj_consume_token(STRING);
      subOpMember = mediator.buildSubOperationMemberString( EQLUtils.eqlToJava(t.image) );
      break;
    case NULL:
      t = jj_consume_token(NULL);
      subOpMember = mediator.buildSubOperationMemberNull();
      break;
    default:
      jj_la1[28] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    {if (true) return subOpMember;}
    throw new Error("Missing return statement in function");
  }

//*********************
// IN (inner) OPERATION
//*********************

//
// begin in operation
//
  final public EQLReqOp in_op_attr(EQLIntMediator mediator) throws ParseException, EQLException {
  EQLReqOp parent = new EQLReqOp();
  EQLReqSubOpMember subOpMember;
    if (jj_2_5(2)) {
      subOpMember = enumeration(mediator);
    } else {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 45:
        subOpMember = subquery(mediator);
        break;
      case FUNCTION:
        subOpMember = function(mediator);
        break;
      default:
        jj_la1[29] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    mediator.addSubOp( new NoneOp(subOpMember), parent );
    {if (true) return parent;}
    throw new Error("Missing return statement in function");
  }

//
// function
//
  final public EQLReqSubOpMember function(EQLIntMediator mediator) throws ParseException, EQLException {
  Token t;
  String name;
  EQLReqSubOpMemberFunc func;
    t = jj_consume_token(FUNCTION);
    name = t.image.substring( 0, t.image.length()-1 );
    func = mediator.getFunction( name );
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case NULL:
    case PARAM:
    case NUMBER:
    case STRING:
    case ID:
    case LISTID:
    case FUNCTION:
    case 45:
      function1(mediator, func);
      break;
    default:
      jj_la1[30] = jj_gen;
      ;
    }
    jj_consume_token(46);
    {if (true) return mediator.buildSubOperationMemberFunc( func );}
    throw new Error("Missing return statement in function");
  }

//
// function params
//
  final public void function1(EQLIntMediator mediator, EQLReqSubOpMemberFunc func) throws ParseException, EQLException {
  EQLReqOp parameter;
    parameter = op_attr(mediator);
    mediator.addFunctionParameter( func, parameter );
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 44:
      jj_consume_token(44);
      function1(mediator, func);
      break;
    default:
      jj_la1[31] = jj_gen;
      ;
    }
  }

//
// enumeration
//
  final public EQLReqSubOpMember enumeration(EQLIntMediator mediator) throws ParseException, EQLException {
  EQLReqSubOpMemberEnum enumVar;
    jj_consume_token(45);
    enumVar = new EQLReqSubOpMemberEnum();
    enumeration1(mediator, enumVar);
    jj_consume_token(46);
    {if (true) return enumVar;}
    throw new Error("Missing return statement in function");
  }

//
// enumeration params
//
  final public void enumeration1(EQLIntMediator mediator, EQLReqSubOpMemberEnum enumVar) throws ParseException, EQLException {
  EQLObject parameter;
    parameter = constants(mediator);
    mediator.addEnumParameter( enumVar, parameter );
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 44:
      jj_consume_token(44);
      enumeration1(mediator, enumVar);
      break;
    default:
      jj_la1[32] = jj_gen;
      ;
    }
  }

//
// subquery
//
  final public EQLReqSubOpMember subquery(EQLIntMediator mediator) throws ParseException, EQLException {
  EQLIntMediator subqueryMediator;
    jj_consume_token(45);
    subqueryMediator = (EQLIntMediator) mediator.clone();
    process(subqueryMediator);
    jj_consume_token(46);
    {if (true) return subqueryMediator.getEQLReq();}
    throw new Error("Missing return statement in function");
  }

//
// aggregate function
//
  final public void aggregate_func(EQLIntMediator mediator) throws ParseException, EQLException {
  EQLReqSubOpMember member;
    member = function(mediator);
    mediator.addSelectColumnAsFunc( (EQLReqSubOpMemberFunc)member );
  }

  final private boolean jj_2_1(int xla) {
    jj_la = xla; jj_lastpos = jj_scanpos = token;
    try { return !jj_3_1(); }
    catch(LookaheadSuccess ls) { return true; }
    finally { jj_save(0, xla); }
  }

  final private boolean jj_2_2(int xla) {
    jj_la = xla; jj_lastpos = jj_scanpos = token;
    try { return !jj_3_2(); }
    catch(LookaheadSuccess ls) { return true; }
    finally { jj_save(1, xla); }
  }

  final private boolean jj_2_3(int xla) {
    jj_la = xla; jj_lastpos = jj_scanpos = token;
    try { return !jj_3_3(); }
    catch(LookaheadSuccess ls) { return true; }
    finally { jj_save(2, xla); }
  }

  final private boolean jj_2_4(int xla) {
    jj_la = xla; jj_lastpos = jj_scanpos = token;
    try { return !jj_3_4(); }
    catch(LookaheadSuccess ls) { return true; }
    finally { jj_save(3, xla); }
  }

  final private boolean jj_2_5(int xla) {
    jj_la = xla; jj_lastpos = jj_scanpos = token;
    try { return !jj_3_5(); }
    catch(LookaheadSuccess ls) { return true; }
    finally { jj_save(4, xla); }
  }

  final private boolean jj_3R_42() {
    if (jj_scan_token(GT)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  final private boolean jj_3R_48() {
    if (jj_scan_token(45)) return true;
    if (jj_3R_26()) return true;
    if (jj_scan_token(46)) return true;
    return false;
  }

  final private boolean jj_3R_41() {
    if (jj_scan_token(EQ)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  final private boolean jj_3R_40() {
    if (jj_scan_token(NE)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  final private boolean jj_3R_10() {
    if (jj_3R_17()) return true;
    return false;
  }

  final private boolean jj_3R_39() {
    if (jj_scan_token(LTEQ)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  final private boolean jj_3R_8() {
    if (jj_3R_15()) return true;
    return false;
  }

  final private boolean jj_3R_9() {
    if (jj_3R_16()) return true;
    return false;
  }

  final private boolean jj_3R_38() {
    if (jj_scan_token(GTEQ)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  final private boolean jj_3R_7() {
    if (jj_scan_token(LISTID)) return true;
    return false;
  }

  final private boolean jj_3R_34() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_38()) {
    jj_scanpos = xsp;
    if (jj_3R_39()) {
    jj_scanpos = xsp;
    if (jj_3R_40()) {
    jj_scanpos = xsp;
    if (jj_3R_41()) {
    jj_scanpos = xsp;
    if (jj_3R_42()) {
    jj_scanpos = xsp;
    if (jj_3R_43()) {
    jj_scanpos = xsp;
    if (jj_3R_44()) {
    jj_scanpos = xsp;
    if (jj_3R_45()) {
    jj_scanpos = xsp;
    if (jj_3R_46()) return true;
    }
    }
    }
    }
    }
    }
    }
    }
    return false;
  }

  final private boolean jj_3R_27() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_34()) {
    jj_scanpos = xsp;
    if (jj_3R_35()) return true;
    }
    return false;
  }

  final private boolean jj_3R_6() {
    if (jj_scan_token(ID)) return true;
    return false;
  }

  final private boolean jj_3R_18() {
    if (jj_3R_26()) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_27()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_64() {
    if (jj_3R_16()) return true;
    return false;
  }

  final private boolean jj_3R_5() {
    if (jj_scan_token(PARAM)) return true;
    return false;
  }

  final private boolean jj_3R_2() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_5()) {
    jj_scanpos = xsp;
    if (jj_3R_6()) {
    jj_scanpos = xsp;
    if (jj_3R_7()) {
    jj_scanpos = xsp;
    if (jj_3R_8()) {
    jj_scanpos = xsp;
    if (jj_3R_9()) {
    jj_scanpos = xsp;
    if (jj_3R_10()) return true;
    }
    }
    }
    }
    }
    return false;
  }

  final private boolean jj_3R_53() {
    if (jj_3R_37()) return true;
    return false;
  }

  final private boolean jj_3R_1() {
    if (jj_scan_token(45)) return true;
    if (jj_3R_4()) return true;
    if (jj_scan_token(46)) return true;
    return false;
  }

  final private boolean jj_3R_17() {
    if (jj_scan_token(45)) return true;
    if (jj_3R_25()) return true;
    if (jj_scan_token(46)) return true;
    return false;
  }

  final private boolean jj_3R_52() {
    if (jj_scan_token(MULT)) return true;
    if (jj_3R_32()) return true;
    return false;
  }

  final private boolean jj_3R_51() {
    if (jj_scan_token(DIV)) return true;
    if (jj_3R_32()) return true;
    return false;
  }

  final private boolean jj_3R_20() {
    if (jj_scan_token(OR)) return true;
    return false;
  }

  final private boolean jj_3_1() {
    if (jj_3R_1()) return true;
    return false;
  }

  final private boolean jj_3R_58() {
    if (jj_scan_token(44)) return true;
    if (jj_3R_11()) return true;
    return false;
  }

  final private boolean jj_3R_19() {
    if (jj_scan_token(AND)) return true;
    return false;
  }

  final private boolean jj_3R_50() {
    if (jj_scan_token(MINUS)) return true;
    if (jj_3R_32()) return true;
    return false;
  }

  final private boolean jj_3R_14() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_19()) {
    jj_scanpos = xsp;
    if (jj_3R_20()) return true;
    }
    if (jj_3R_4()) return true;
    return false;
  }

  final private boolean jj_3R_11() {
    if (jj_3R_15()) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_58()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_13() {
    if (jj_3R_18()) return true;
    return false;
  }

  final private boolean jj_3R_49() {
    if (jj_scan_token(PLUS)) return true;
    if (jj_3R_32()) return true;
    return false;
  }

  final private boolean jj_3R_12() {
    if (jj_3R_1()) return true;
    return false;
  }

  final private boolean jj_3R_37() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_49()) {
    jj_scanpos = xsp;
    if (jj_3R_50()) {
    jj_scanpos = xsp;
    if (jj_3R_51()) {
    jj_scanpos = xsp;
    if (jj_3R_52()) return true;
    }
    }
    }
    xsp = jj_scanpos;
    if (jj_3R_53()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_4() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_12()) {
    jj_scanpos = xsp;
    if (jj_3R_13()) return true;
    }
    xsp = jj_scanpos;
    if (jj_3R_14()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_70() {
    if (jj_3R_4()) return true;
    return false;
  }

  final private boolean jj_3R_3() {
    if (jj_scan_token(45)) return true;
    if (jj_3R_11()) return true;
    if (jj_scan_token(46)) return true;
    return false;
  }

  final private boolean jj_3R_36() {
    if (jj_3R_48()) return true;
    return false;
  }

  final private boolean jj_3_4() {
    if (jj_3R_2()) return true;
    return false;
  }

  final private boolean jj_3R_78() {
    if (jj_scan_token(44)) return true;
    if (jj_3R_61()) return true;
    return false;
  }

  final private boolean jj_3R_32() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3_4()) {
    jj_scanpos = xsp;
    if (jj_3R_36()) return true;
    }
    return false;
  }

  final private boolean jj_3R_59() {
    if (jj_scan_token(44)) return true;
    if (jj_3R_28()) return true;
    return false;
  }

  final private boolean jj_3R_77() {
    if (jj_scan_token(44)) return true;
    if (jj_3R_61()) return true;
    return false;
  }

  final private boolean jj_3R_69() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_78()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_28() {
    if (jj_3R_26()) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_59()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_68() {
    if (jj_scan_token(ID)) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_77()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_33() {
    if (jj_3R_37()) return true;
    return false;
  }

  final private boolean jj_3R_67() {
    if (jj_scan_token(SELECT_ALL_COLUMNS)) return true;
    return false;
  }

  final private boolean jj_3R_61() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_67()) {
    jj_scanpos = xsp;
    if (jj_3R_68()) {
    jj_scanpos = xsp;
    if (jj_3R_69()) return true;
    }
    }
    return false;
  }

  final private boolean jj_3R_26() {
    if (jj_3R_32()) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_33()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_76() {
    if (jj_3R_66()) return true;
    return false;
  }

  final private boolean jj_3R_24() {
    if (jj_3R_28()) return true;
    return false;
  }

  final private boolean jj_3R_16() {
    if (jj_scan_token(FUNCTION)) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_24()) jj_scanpos = xsp;
    if (jj_scan_token(46)) return true;
    return false;
  }

  final private boolean jj_3R_75() {
    if (jj_scan_token(LIST)) return true;
    return false;
  }

  final private boolean jj_3R_74() {
    if (jj_scan_token(NUMBER)) return true;
    return false;
  }

  final private boolean jj_3R_73() {
    if (jj_scan_token(FALSE)) return true;
    return false;
  }

  final private boolean jj_3R_80() {
    if (jj_scan_token(44)) return true;
    if (jj_3R_71()) return true;
    return false;
  }

  final private boolean jj_3R_72() {
    if (jj_scan_token(TRUE)) return true;
    return false;
  }

  final private boolean jj_3R_82() {
    if (jj_scan_token(DESC)) return true;
    return false;
  }

  final private boolean jj_3R_66() {
    if (jj_scan_token(ID)) return true;
    if (jj_scan_token(EQ)) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_72()) {
    jj_scanpos = xsp;
    if (jj_3R_73()) {
    jj_scanpos = xsp;
    if (jj_3R_74()) {
    jj_scanpos = xsp;
    if (jj_3R_75()) return true;
    }
    }
    }
    xsp = jj_scanpos;
    if (jj_scan_token(44)) jj_scanpos = xsp;
    xsp = jj_scanpos;
    if (jj_3R_76()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_81() {
    if (jj_scan_token(ASC)) return true;
    return false;
  }

  final private boolean jj_3R_79() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_81()) {
    jj_scanpos = xsp;
    if (jj_3R_82()) return true;
    }
    return false;
  }

  final private boolean jj_3R_57() {
    if (jj_3R_16()) return true;
    return false;
  }

  final private boolean jj_3R_71() {
    if (jj_scan_token(ID)) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_79()) jj_scanpos = xsp;
    xsp = jj_scanpos;
    if (jj_3R_80()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_56() {
    if (jj_3R_17()) return true;
    return false;
  }

  final private boolean jj_3_5() {
    if (jj_3R_3()) return true;
    return false;
  }

  final private boolean jj_3R_54() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3_5()) {
    jj_scanpos = xsp;
    if (jj_3R_56()) {
    jj_scanpos = xsp;
    if (jj_3R_57()) return true;
    }
    }
    return false;
  }

  final private boolean jj_3R_65() {
    if (jj_scan_token(WHERE)) return true;
    if (jj_3R_70()) return true;
    return false;
  }

  final private boolean jj_3R_31() {
    if (jj_scan_token(NEW)) return true;
    if (jj_scan_token(ID)) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_scan_token(43)) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_47() {
    if (jj_scan_token(IS)) return true;
    if (jj_scan_token(NOT)) return true;
    if (jj_scan_token(NULL)) return true;
    return false;
  }

  final private boolean jj_3R_63() {
    if (jj_scan_token(ORDER)) return true;
    if (jj_scan_token(BY)) return true;
    if (jj_3R_71()) return true;
    return false;
  }

  final private boolean jj_3R_30() {
    if (jj_scan_token(AGGREGATE)) return true;
    if (jj_3R_64()) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_65()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_62() {
    if (jj_scan_token(WHERE)) return true;
    if (jj_3R_70()) return true;
    return false;
  }

  final private boolean jj_3R_29() {
    if (jj_scan_token(SELECT)) return true;
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_60()) jj_scanpos = xsp;
    if (jj_3R_61()) return true;
    xsp = jj_scanpos;
    if (jj_3R_62()) jj_scanpos = xsp;
    xsp = jj_scanpos;
    if (jj_3R_63()) jj_scanpos = xsp;
    return false;
  }

  final private boolean jj_3R_25() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_29()) {
    jj_scanpos = xsp;
    if (jj_3R_30()) {
    jj_scanpos = xsp;
    if (jj_3R_31()) return true;
    }
    }
    return false;
  }

  final private boolean jj_3R_60() {
    if (jj_scan_token(41)) return true;
    if (jj_3R_66()) return true;
    if (jj_scan_token(42)) return true;
    return false;
  }

  final private boolean jj_3_3() {
    if (jj_scan_token(IS)) return true;
    if (jj_scan_token(NULL)) return true;
    return false;
  }

  final private boolean jj_3R_35() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3_3()) {
    jj_scanpos = xsp;
    if (jj_3R_47()) return true;
    }
    return false;
  }

  final private boolean jj_3R_55() {
    if (jj_scan_token(NOT)) return true;
    if (jj_scan_token(IN)) return true;
    if (jj_3R_54()) return true;
    return false;
  }

  final private boolean jj_3R_23() {
    if (jj_scan_token(NULL)) return true;
    return false;
  }

  final private boolean jj_3_2() {
    if (jj_scan_token(NOT)) return true;
    if (jj_scan_token(LIKE)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  final private boolean jj_3R_22() {
    if (jj_scan_token(STRING)) return true;
    return false;
  }

  final private boolean jj_3R_46() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3_2()) {
    jj_scanpos = xsp;
    if (jj_3R_55()) return true;
    }
    return false;
  }

  final private boolean jj_3R_21() {
    if (jj_scan_token(NUMBER)) return true;
    return false;
  }

  final private boolean jj_3R_45() {
    if (jj_scan_token(IN)) return true;
    if (jj_3R_54()) return true;
    return false;
  }

  final private boolean jj_3R_15() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_21()) {
    jj_scanpos = xsp;
    if (jj_3R_22()) {
    jj_scanpos = xsp;
    if (jj_3R_23()) return true;
    }
    }
    return false;
  }

  final private boolean jj_3R_44() {
    if (jj_scan_token(LIKE)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  final private boolean jj_3R_43() {
    if (jj_scan_token(LT)) return true;
    if (jj_3R_26()) return true;
    return false;
  }

  public EQLParserGenericImplTokenManager token_source;
  SimpleCharStream jj_input_stream;
  public Token token, jj_nt;
  private int jj_ntk;
  private Token jj_scanpos, jj_lastpos;
  private int jj_la;
  public boolean lookingAhead = false;
  private boolean jj_semLA;
  private int jj_gen;
  final private int[] jj_la1 = new int[33];
  static private int[] jj_la1_0;
  static private int[] jj_la1_1;
  static {
      jj_la1_0();
      jj_la1_1();
   }
   private static void jj_la1_0() {
      jj_la1_0 = new int[] {0x0,0x200,0x400,0x200,0x0,0x1c0,0x300000,0x0,0x0,0x0,0x0,0x0,0x8000,0x30000,0x30000,0x4000,0x1fc06000,0x1000,0x1fc07000,0x1fc07000,0xc0000,0xc0000,0x0,0xe0000000,0x0,0xe0000000,0xe0000000,0x8000,0x8000,0x0,0x8000,0x0,0x0,};
   }
   private static void jj_la1_1() {
      jj_la1_1 = new int[] {0x200,0x0,0x0,0x0,0x800,0x0,0x104,0x1000,0x10,0x1000,0x1000,0x90,0x207e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1000,0x1,0x2000,0x1,0x1,0x207e,0xc,0x2040,0x207e,0x1000,0x1000,};
   }
  final private JJCalls[] jj_2_rtns = new JJCalls[5];
  private boolean jj_rescan = false;
  private int jj_gc = 0;

  public EQLParserGenericImpl(java.io.InputStream stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new EQLParserGenericImplTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 33; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  public void ReInit(java.io.InputStream 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 < 33; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  public EQLParserGenericImpl(java.io.Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new EQLParserGenericImplTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 33; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  public void ReInit(java.io.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 < 33; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  public EQLParserGenericImpl(EQLParserGenericImplTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 33; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  public void ReInit(EQLParserGenericImplTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 33; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  final 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++;
      if (++jj_gc > 100) {
        jj_gc = 0;
        for (int i = 0; i < jj_2_rtns.length; i++) {
          JJCalls c = jj_2_rtns[i];
          while (c != null) {
            if (c.gen < jj_gen) c.first = null;
            c = c.next;
          }
        }
      }
      return token;
    }
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  }

  static private final class LookaheadSuccess extends java.lang.Error { }
  final private LookaheadSuccess jj_ls = new LookaheadSuccess();
  final private boolean jj_scan_token(int kind) {
    if (jj_scanpos == jj_lastpos) {
      jj_la--;
      if (jj_scanpos.next == null) {
        jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
      } else {
        jj_lastpos = jj_scanpos = jj_scanpos.next;
      }
    } else {
      jj_scanpos = jj_scanpos.next;
    }
    if (jj_rescan) {
      int i = 0; Token tok = token;
      while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
      if (tok != null) jj_add_error_token(kind, i);
    }
    if (jj_scanpos.kind != kind) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
    return false;
  }

  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;
  }

  final public Token getToken(int index) {
    Token t = lookingAhead ? jj_scanpos : token;
    for (int i = 0; i < index; i++) {
      if (t.next != null) t = t.next;
      else t = t.next = token_source.getNextToken();
    }
    return t;
  }

  final 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.Vector jj_expentries = new java.util.Vector();
  private int[] jj_expentry;
  private int jj_kind = -1;
  private int[] jj_lasttokens = new int[100];
  private int jj_endpos;

  private void jj_add_error_token(int kind, int pos) {
    if (pos >= 100) return;
    if (pos == jj_endpos + 1) {
      jj_lasttokens[jj_endpos++] = kind;
    } else if (jj_endpos != 0) {
      jj_expentry = new int[jj_endpos];
      for (int i = 0; i < jj_endpos; i++) {
        jj_expentry[i] = jj_lasttokens[i];
      }
      boolean exists = false;
      for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) {
        int[] oldentry = (int[])(e.nextElement());
        if (oldentry.length == jj_expentry.length) {
          exists = true;
          for (int i = 0; i < jj_expentry.length; i++) {
            if (oldentry[i] != jj_expentry[i]) {
              exists = false;
              break;
            }
          }
          if (exists) break;
        }
      }
      if (!exists) jj_expentries.addElement(jj_expentry);
      if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
    }
  }

  public ParseException generateParseException() {
    jj_expentries.removeAllElements();
    boolean[] la1tokens = new boolean[47];
    for (int i = 0; i < 47; i++) {
      la1tokens[i] = false;
    }
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 33; 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 < 47; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.addElement(jj_expentry);
      }
    }
    jj_endpos = 0;
    jj_rescan_token();
    jj_add_error_token(0, 0);
    int[][] exptokseq = new int[jj_expentries.size()][];
    for (int i = 0; i < jj_expentries.size(); i++) {
      exptokseq[i] = (int[])jj_expentries.elementAt(i);
    }
    return new ParseException(token, exptokseq, tokenImage);
  }

  final public void enable_tracing() {
  }

  final public void disable_tracing() {
  }

  final private void jj_rescan_token() {
    jj_rescan = true;
    for (int i = 0; i < 5; i++) {
      JJCalls p = jj_2_rtns[i];
      do {
        if (p.gen > jj_gen) {
          jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
          switch (i) {
            case 0: jj_3_1(); break;
            case 1: jj_3_2(); break;
            case 2: jj_3_3(); break;
            case 3: jj_3_4(); break;
            case 4: jj_3_5(); break;
          }
        }
        p = p.next;
      } while (p != null);
    }
    jj_rescan = false;
  }

  final private void jj_save(int index, int xla) {
    JJCalls p = jj_2_rtns[index];
    while (p.gen > jj_gen) {
      if (p.next == null) { p = p.next = new JJCalls(); break; }
      p = p.next;
    }
    p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
  }

  static final class JJCalls {
    int gen;
    Token first;
    int arg;
    JJCalls next;
  }

}
