All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fuwjax.oss.expression.WontonExpressionParser Maven / Gradle / Ivy

/* Generated By:JavaCC: Do not edit this line. WontonExpressionParser.java */
package org.fuwjax.oss.expression;

public class WontonExpressionParser implements WontonExpressionParserConstants {

  final public Expression Expression() throws ParseException {
    Expression x, t, e;
    x = OrExpression();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case THEN:
      jj_consume_token(THEN);
      t = Expression();
      jj_consume_token(ELSE);
      e = Expression();
      x = new TernaryExpression(x, t, e);
      break;
    default:
      jj_la1[0] = jj_gen;
      ;
    }
    {if (true) return x;}
    throw new Error("Missing return statement in function");
  }

  final public Expression OrExpression() throws ParseException {
    Expression x, t;
    x = AndExpression();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case OR:
        ;
        break;
      default:
        jj_la1[1] = jj_gen;
        break label_1;
      }
      jj_consume_token(OR);
      t = AndExpression();
      x = Operation.OR.of(x, t);
    }
    {if (true) return x;}
    throw new Error("Missing return statement in function");
  }

  final public Expression AndExpression() throws ParseException {
    Expression x, t;
    x = RelationalExpression();
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case AND:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_2;
      }
      jj_consume_token(AND);
      t = RelationalExpression();
      x = Operation.AND.of(x, t);
    }
    {if (true) return x;}
    throw new Error("Missing return statement in function");
  }

  final public Expression RelationalExpression() throws ParseException {
    Expression x, t;
    Operation o;
    x = AdditiveExpression();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case EQ:
    case NE:
    case LT:
    case GT:
    case LE:
    case GE:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case EQ:
        jj_consume_token(EQ);
             o = Operation.EQ;
        break;
      case NE:
        jj_consume_token(NE);
             o = Operation.NE;
        break;
      case LT:
        jj_consume_token(LT);
            o = Operation.LT;
        break;
      case GT:
        jj_consume_token(GT);
            o = Operation.GT;
        break;
      case LE:
        jj_consume_token(LE);
             o = Operation.LE;
        break;
      case GE:
        jj_consume_token(GE);
             o = Operation.GE;
        break;
      default:
        jj_la1[3] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      t = AdditiveExpression();
      x = o.of(x, t);
      break;
    default:
      jj_la1[4] = jj_gen;
      ;
    }
    {if (true) return x;}
    throw new Error("Missing return statement in function");
  }

  final public Expression AdditiveExpression() throws ParseException {
    Expression x, t;
    Operation o;
    x = MultiplicativeExpression();
    label_3:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case ADD:
      case SUB:
        ;
        break;
      default:
        jj_la1[5] = jj_gen;
        break label_3;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case ADD:
        jj_consume_token(ADD);
            o = Operation.ADD;
        break;
      case SUB:
        jj_consume_token(SUB);
            o = Operation.SUB;
        break;
      default:
        jj_la1[6] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      t = MultiplicativeExpression();
      x = o.of(x, t);
    }
    {if (true) return x;}
    throw new Error("Missing return statement in function");
  }

  final public Expression MultiplicativeExpression() throws ParseException {
    Expression x, t;
    Operation o;
    x = UnaryExpression();
    label_4:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MUL:
      case DIV:
      case MOD:
        ;
        break;
      default:
        jj_la1[7] = jj_gen;
        break label_4;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MUL:
        jj_consume_token(MUL);
            o = Operation.MUL;
        break;
      case DIV:
        jj_consume_token(DIV);
            o = Operation.DIV;
        break;
      case MOD:
        jj_consume_token(MOD);
            o = Operation.MOD;
        break;
      default:
        jj_la1[8] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      t = UnaryExpression();
      x = o.of(x, t);
    }
    {if (true) return x;}
    throw new Error("Missing return statement in function");
  }

  final public Expression UnaryExpression() throws ParseException {
    Expression x;
    Operation o = Operation.POS;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case NOT:
    case ADD:
    case SUB:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case ADD:
        jj_consume_token(ADD);
            o = Operation.POS;
        break;
      case SUB:
        jj_consume_token(SUB);
            o = Operation.NEG;
        break;
      case NOT:
        jj_consume_token(NOT);
            o = Operation.NOT;
        break;
      default:
        jj_la1[9] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      break;
    default:
      jj_la1[10] = jj_gen;
      ;
    }
    x = PrimaryExpression();
    {if (true) return o.of(x);}
    throw new Error("Missing return statement in function");
  }

  final public Expression PrimaryExpression() throws ParseException {
    Expression x;
    PathExpression p;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case NULL:
      jj_consume_token(NULL);
             x = Constant.NULL;
      break;
    case TRUE:
      jj_consume_token(TRUE);
             x = Constant.TRUE;
      break;
    case FALSE:
      jj_consume_token(FALSE);
              x = Constant.FALSE;
      break;
    case NUMBER:
      jj_consume_token(NUMBER);
               x = Constant.numberOf(token.image);
      break;
    case LP:
      jj_consume_token(LP);
      x = Expression();
      jj_consume_token(RP);
      break;
    case IDENT:
      jj_consume_token(IDENT);
              p = new PathExpression(token.image);
      label_5:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case LB:
        case DOT:
          ;
          break;
        default:
          jj_la1[11] = jj_gen;
          break label_5;
        }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case LB:
          jj_consume_token(LB);
          jj_consume_token(INT);
                  p = p.sub(token.image);
          jj_consume_token(RB);
          break;
        case DOT:
          jj_consume_token(DOT);
          jj_consume_token(IDENT);
                    p = p.sub(token.image);
          break;
        default:
          jj_la1[12] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
      }
      x = p;
      break;
    default:
      jj_la1[13] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    {if (true) return x;}
    throw new Error("Missing return statement in function");
  }

  /** Generated Token Manager. */
  public WontonExpressionParserTokenManager token_source;
  JavaCharStream 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[14];
  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[] {0x20000,0x80000,0x100000,0x7e00000,0x7e00000,0x30000000,0x30000000,0xc0000000,0xc0000000,0x38000000,0x38000000,0x12000,0x12000,0x91e,};
   }
   private static void jj_la1_init_1() {
      jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x0,0x0,};
   }

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

  /** Reinitialise. */
  public void ReInit(java.io.InputStream stream) {
     ReInit(stream, null);
  }
  /** Reinitialise. */
  public void ReInit(java.io.InputStream stream, String encoding) {
    try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.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 < 14; i++) jj_la1[i] = -1;
  }

  /** Constructor. */
  public WontonExpressionParser(java.io.Reader stream) {
    jj_input_stream = new JavaCharStream(stream, 1, 1);
    token_source = new WontonExpressionParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 14; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  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 < 14; i++) jj_la1[i] = -1;
  }

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

  /** Reinitialise. */
  public void ReInit(WontonExpressionParserTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 14; 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 java.util.ArrayList();
  private int[] jj_expentry;
  private int jj_kind = -1;

  /** Generate ParseException. */
  public ParseException generateParseException() {
    jj_expentries.clear();
    boolean[] la1tokens = new boolean[33];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 14; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<




© 2015 - 2024 Weber Informatics LLC | Privacy Policy