Example #1
0
 public void parse() throws IOException {
   sta.nextTokenType();
   cond();
   if (sta.lastToken() != TOKEN_EOF)
     throw new InvalidExpressionError(
         "Expected end of expression. Got '" + sta.lastToken() + "' instead.");
 }
Example #2
0
 private void factb() throws IOException {
   switch (sta.lastToken()) {
     case TOKEN_NOT:
       sta.nextTokenType();
       factb();
       builder.buildOperator(OP_NOT);
       break;
     case TOKEN_OPAR:
       sta.nextTokenType();
       cond();
       if (sta.lastToken() != TOKEN_CPAR)
         throw new InvalidExpressionError("Expected ). Got '" + sta.lastToken() + "' instead.");
       sta.nextTokenType();
       break;
     case TOKEN_ADD:
     case TOKEN_SUB:
     case TOKEN_ID:
     case TOKEN_NUM:
     case TOKEN_OSB:
       expr();
       switch (sta.lastToken()) {
         case TOKEN_EQ:
           builder.buildOperator(OP_EQ);
           break;
         case TOKEN_NE:
           builder.buildOperator(OP_NE);
           break;
         case TOKEN_GT:
           builder.buildOperator(OP_GT);
           break;
         case TOKEN_GE:
           builder.buildOperator(OP_GE);
           break;
         case TOKEN_LT:
           builder.buildOperator(OP_LT);
           break;
         case TOKEN_LE:
           builder.buildOperator(OP_LE);
           break;
         default:
           throw new InvalidExpressionError(
               "Expected relational operator (==, !=, >, >=, <, <=). Got '"
                   + sta.lastToken()
                   + "' instead.");
       }
       sta.nextTokenType();
       expr();
       builder.endOperator();
       break;
     default:
       throw new InvalidExpressionError(
           "Expected not (!), (, [, +, -, a number or an identifier. Got '"
               + sta.lastToken()
               + "' instead.");
   }
 }