Exemplo n.º 1
0
 /** Comparison operator */
 public void operatorCompare(
     HplsqlParser.Bool_expr_binaryContext ctx, HplsqlParser.Bool_expr_binary_operatorContext op) {
   Var v1 = evalPop(ctx.expr(0));
   Var v2 = evalPop(ctx.expr(1));
   int cmp = v1.compareTo(v2);
   boolean bool = false;
   if (op.T_GREATER() != null) {
     if (cmp > 0) {
       bool = true;
     }
   } else if (op.T_GREATEREQUAL() != null) {
     if (cmp >= 0) {
       bool = true;
     }
   }
   if (op.T_LESS() != null) {
     if (cmp < 0) {
       bool = true;
     }
   } else if (op.T_LESSEQUAL() != null) {
     if (cmp <= 0) {
       bool = true;
     }
   }
   exec.stackPush(bool);
 }
Exemplo n.º 2
0
 /** Unary boolean expression */
 public Integer execBoolUnary(HplsqlParser.Bool_expr_unaryContext ctx) {
   boolean val = false;
   if (ctx.T_IS() != null) {
     val = evalPop(ctx.expr(0)).isNull();
     if (ctx.T_NOT() != null) {
       val = !val;
     }
   } else if (ctx.T_BETWEEN() != null) {
     Var v = evalPop(ctx.expr(0));
     Var v1 = evalPop(ctx.expr(1));
     int cmp = v.compareTo(v1);
     if (cmp >= 0) {
       Var v2 = evalPop(ctx.expr(2));
       cmp = v.compareTo(v2);
       if (cmp <= 0) {
         val = true;
       }
     }
   }
   exec.stackPush(val);
   return 0;
 }
Exemplo n.º 3
0
 /** Simple CASE expression */
 public void execSimpleCase(HplsqlParser.Expr_case_simpleContext ctx) {
   int i = 1;
   int cnt = ctx.expr().size();
   boolean found = false;
   Var val = evalPop(ctx.expr(0));
   while (i < cnt) {
     Var when = evalPop(ctx.expr(i));
     if (val.compareTo(when) == 0) {
       visit(ctx.expr(i + 1));
       found = true;
       break;
     }
     i += 2;
   }
   if (!found) {
     if (ctx.T_ELSE() != null) {
       visit(ctx.expr(cnt - 1));
     } else {
       evalNull();
     }
   }
 }