Esempio n. 1
0
  public static final int expr() throws ParseException {
    Token t;
    int t1, t2;
    Operation op = null;
    // <expr> 	::= <term> {(+|-) <term>}
    t1 = term();
    label_2:
    while (true) {
      switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case PLUS:
        case MINUS:;
          break;
        default:
          jj_la1[1] = jj_gen;
          break label_2;
      }
      switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case PLUS:
          t = jj_consume_token(PLUS);
          System.out.printf(
              "@(%d,%d)\u005ctPLUS\u005ct-\u005ct%s\u005cn", t.beginLine, t.beginColumn, t);
          op = new Sum();
          break;
        case MINUS:
          t = jj_consume_token(MINUS);
          System.out.printf(
              "@(%d,%d)\u005ctMINUS\u005ct-\u005ct%s\u005cn", t.beginLine, t.beginColumn, t);
          op = new Sub();
          break;
        default:
          jj_la1[2] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
      }
      t2 = term();
      t1 = op.calculate(t1, t2);
      // System.out.println("<TERM>" + t.beginLine + " " + t.beginColumn);

    }
    {
      if (true) return t1;
    }
    throw new Error("Missing return statement in function");
  }
Esempio n. 2
0
 public static final int term() throws ParseException {
   Token t;
   int f1, f2;
   Operation op = null;
   // <term> 	::= <factor> {(*|/) <factor>}
   f1 = factor();
   label_3:
   while (true) {
     switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
       case MUL:
       case DIV:;
         break;
       default:
         jj_la1[3] = jj_gen;
         break label_3;
     }
     switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
       case MUL:
         t = jj_consume_token(MUL);
         op = new Mul();
         System.out.printf(
             "@(%d,%d)\u005ctMUL\u005ct-\u005ct%s\u005cn", t.beginLine, t.beginColumn, t);
         break;
       case DIV:
         t = jj_consume_token(DIV);
         op = new Div();
         System.out.printf(
             "@(%d,%d)\u005ctDIV\u005ct-\u005ct%s\u005cn", t.beginLine, t.beginColumn, t);
         break;
       default:
         jj_la1[4] = jj_gen;
         jj_consume_token(-1);
         throw new ParseException();
     }
     f2 = factor();
     f1 = op.calculate(f1, f2);
   }
   {
     if (true) return f1;
   }
   throw new Error("Missing return statement in function");
 }