示例#1
0
文件: Parser.java 项目: teknoraver/is
 private void expr() throws IOException {
   switch (sta.lastToken()) {
     case TOKEN_SUB:
       // 0 - term
       builder.buildOperand(0);
       builder.buildOperator(OP_SUB);
       sta.nextTokenType();
       term();
       builder.endOperator();
       expr1();
       break;
     case TOKEN_ADD:
       sta.nextTokenType();
       term();
       expr1();
       break;
     case TOKEN_ID:
     case TOKEN_NUM:
     case TOKEN_OSB:
       term();
       expr1();
       break;
     default:
       throw new InvalidExpressionError(
           "Expected [, a number with sign or an identifier. Got '"
               + sta.lastToken()
               + "' instead.");
   }
 }
示例#2
0
文件: Parser.java 项目: teknoraver/is
 private void cond1() throws IOException {
   if (sta.lastToken() == TOKEN_OR) {
     builder.buildOperator(OP_OR);
     sta.nextTokenType();
     termb();
     builder.endOperator();
     cond1();
   }
 }
示例#3
0
文件: Parser.java 项目: teknoraver/is
 private void termp1() throws IOException {
   if (sta.lastToken() == TOKEN_POW) {
     sta.nextTokenType();
     builder.buildOperator(OP_POW);
     fact();
     builder.endOperator();
     termp1();
   }
 }
示例#4
0
文件: Parser.java 项目: teknoraver/is
 private void expr1() throws IOException {
   if (sta.lastToken() == TOKEN_ADD) builder.buildOperator(OP_ADD);
   else if (sta.lastToken() == TOKEN_SUB) builder.buildOperator(OP_SUB);
   else return;
   sta.nextTokenType();
   term();
   builder.endOperator();
   expr1();
 }
示例#5
0
文件: Parser.java 项目: teknoraver/is
 private void termb1() throws IOException {
   if (sta.lastToken() == TOKEN_AND) {
     builder.buildOperator(OP_AND);
     sta.nextTokenType();
     factb();
     builder.endOperator();
     termb1();
   }
 }
示例#6
0
文件: Parser.java 项目: teknoraver/is
 private void term1() throws IOException {
   if (sta.lastToken() == TOKEN_MUL) builder.buildOperator(OP_MUL);
   else if (sta.lastToken() == TOKEN_DIV) builder.buildOperator(OP_DIV);
   else if (sta.lastToken() == TOKEN_MOD) builder.buildOperator(OP_MOD);
   else return;
   sta.nextTokenType();
   termp();
   builder.endOperator();
   term1();
 }
示例#7
0
文件: Parser.java 项目: teknoraver/is
 private void fact() throws IOException {
   if (sta.lastToken() == TOKEN_ID) {
     builder.buildOperand(sta.getString());
     sta.nextTokenType();
   } else if (sta.lastToken() == TOKEN_NUM) {
     builder.buildOperand(sta.getInt());
     sta.nextTokenType();
   } else if (sta.lastToken() == TOKEN_OSB) {
     sta.nextTokenType();
     expr();
     if (sta.lastToken() != TOKEN_CSB)
       throw new InvalidExpressionError("Expected ]. Got '" + sta.lastToken() + "' instead.");
     sta.nextTokenType();
   } else
     throw new InvalidExpressionError(
         "Expected [, a number or an identifier. Got '" + sta.lastToken() + "' instead.");
 }
示例#8
0
文件: Parser.java 项目: teknoraver/is
 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.");
   }
 }