state_t __2DROP(context_t *ctx) { int x1, x2; if (popnum(ctx->ds, &x2) && popnum(ctx->ds, &x1)) { return OK; } else { return stack_underflow(ctx); } }
state_t __SWAP(context_t *ctx) { int x1, x2; if (popnum(ctx->ds, &x2) && popnum(ctx->ds, &x1)) { pushnum(ctx->ds, x2); pushnum(ctx->ds, x1); return OK; } else { return stack_underflow(ctx); } }
state_t __2OVER(context_t *ctx) { int x1, x2, x3, x4; if (popnum(ctx->ds, &x4) && popnum(ctx->ds, &x3) && popnum(ctx->ds, &x2) && popnum(ctx->ds, &x1)) { pushnum(ctx->ds, x1); pushnum(ctx->ds, x2); pushnum(ctx->ds, x3); pushnum(ctx->ds, x4); pushnum(ctx->ds, x1); pushnum(ctx->ds, x2); return OK; } else { return stack_underflow(ctx); } }
state_t __DROP(context_t *ctx) { int x; if (popnum(ctx->ds, &x)) { return OK; } else { return stack_underflow(ctx); } }
state_t __RDROP(context_t *ctx) { int x; if (popnum(ctx->rs, &x)) { return OK; } else { return error(ctx, -6); // return stack underflow } }
state_t __RFROM(context_t *ctx) { int x1; if (popnum(ctx->rs, &x1)) { pushnum(ctx->ds, x1); return OK; } else { return error(ctx, -6); // return stack underflow } }
state_t __TOR(context_t *ctx) { int x1; if (popnum(ctx->ds, &x1)) { pushnum(ctx->rs, x1); return OK; } else { return stack_underflow(ctx); } }
/* ** VALOF -- compute value of expression ** ** This is the real expression processor. It handles sequencing ** and precedence. ** ** Parameters: ** terminator -- the symbol which should terminate ** the expression. ** ** Returns: ** The value of the expression. ** ** Side Effects: ** Gobbles input. ** ** Requires: ** exprfind -- to read operands. ** opfind -- to read operators. ** exp_op -- to perform operations. ** ** Called By: ** expr ** ** Diagnostics: ** Extra Parenthesis found: assumed typo ** An unmatched right parenthesis was read. ** It was thrown away. ** Insufficient parenthesis found: assumed zero. ** An unmatched left parenthesis was left ** in the operator stack at the end of the ** expression. The value zero was taken ** for the expression. ** ** Syserrs: ** none */ int valof(int terminator) { register int number; register int operator; pushop(SEPERATOR); /* initialize the stack */ for(;;) { number = exprfind(); if (ExprError) return(0); operator = opfind(); if (ExprError) return(0); if (operator == RIGHTP || operator == END) break; /* Do all previous operations with a higher precedence */ while (ExprPrec[operator] <= ExprPrec[ExprOptr[-1]]) number = exp_op(popop(), popnum(), number); pushop(operator); pushnum(number); } if (operator != terminator) /* ExprError in operators */ if (operator == RIGHTP) printf("Extra parenthesis found: assumed typo.\n"); else { ExprError = TRUE; printf("Insufficient parenthesis found: Assumed zero.\n"); return(0); } /* Empty stack for this call of valof */ while ((operator = popop()) != SEPERATOR) number = exp_op(operator, popnum(), number); return(number); }
state_t __PICK(context_t *ctx) { int u; if (popnum(ctx->ds, &u)) { dlist_elem_t *element = dlist_head(ctx->ds); while (u >= 0 && element != NULL) { if (u == 0) { int *num = dlist_data(element); pushnum(ctx->ds, *num); return OK; } u--; element = dlist_next(element); } } return error(ctx, -11); // result out of range }