Example #1
0
 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.");
   }
 }
Example #2
0
 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();
 }