int main (int argc, char **argv) { program_name = basename (argv[0]); scan_options (argc, argv); stack *stack = new_stack (); token *scanner = new_token (stdin); for (;;) { int token = scan_token (scanner); if (token == EOF) break; switch (token) { case NUMBER: do_push (stack, peek_token (scanner)); break; case '+': do_binop (stack, add_bigint); break; case '-': do_binop (stack, sub_bigint); break; case '*': do_binop (stack, mul_bigint); break; case 'c': do_clear (stack); break; case 'f': do_print_all (stack); break; case 'p': do_print (stack); break; default: unimplemented (token); break; } } do_clear(stack); free_stack(stack); free_token(scanner); DEBUGF ('m', "EXIT %d\n", exit_status); return EXIT_SUCCESS; }
int main (int argc, char **argv) { program_name = basename (argv[0]); scan_options (argc, argv); stack *stack = new_stack (); bool quit = false; yy_flex_debug = false; while (! quit) { int token = yylex(); if (token == YYEOF) break; switch (token) { case NUMBER: do_push (stack, yytext); break; case '+': do_binop (stack, add_bigint); break; case '-': do_binop (stack, sub_bigint); break; case '*': do_binop (stack, mul_bigint); break; case 'c': do_clear (stack); break; case 'f': do_print_all (stack); break; case 'p': do_print (stack); break; case 'q': quit = true; break; default: unimplemented (token); break; } } yycleanup(); DEBUGF ('m', "EXIT %d\n", exit_status); do_clear(stack); free_stack(stack); return EXIT_SUCCESS; }
void do_operator (stack *the_stack, const char *oper) { switch (oper[0]) { case '+': do_binop (the_stack, '+'); break; case '-': do_binop (the_stack, '-'); break; case '*': do_binop (the_stack, '*'); break; case '/': do_binop (the_stack, '/'); break; case ';': do_print (the_stack); break; case '@': do_clear (the_stack); break; default : bad_operator (oper); break; } }
void do_operator (stack *the_stack, const char *oper) { switch (*oper) { case '+': do_binop (the_stack, '+'); break; case '-': do_binop (the_stack, '-'); break; case '*': do_binop (the_stack, '*'); break; case '/': do_binop (the_stack, '/'); break; case ';': do_print (the_stack); break; case '@': do_clear (the_stack); break; default : bad_operator (oper); break; } //printf ("the_stack=%p, top=%d, oper=\"%s\"\n", // the_stack, the_stack->top, oper); }
static arith_t binop2(arith_t a, int op, int precedence, int noeval) { for (;;) { union yystype val; arith_t b; int op2; int token; token = yylex(); val = yylval; b = primary(token, &val, yylex(), noeval); op2 = last_token; if (op2 >= ARITH_BINOP_MIN && op2 < ARITH_BINOP_MAX && higher_prec(op2, op)) { b = binop2(b, op2, arith_prec(op), noeval); op2 = last_token; } a = noeval ? b : do_binop(op, a, b); if (op2 < ARITH_BINOP_MIN || op2 >= ARITH_BINOP_MAX || arith_prec(op2) >= precedence) return a; op = op2; } }
static int do_register_op(struct proc *p, int addr, char op, char *opname) { char *temp; int res; temp = get_wordref(p, addr); if (temp == NULL) { fprintf(stderr, "%s: failed to get memory ref\n", opname); return -1; } res = do_binop(p->r, temp, op); if (res < 0) { fprintf(stderr, "%s: do_binop failed\n", opname); return -1; } release_wordref(p, addr); int2word(res, p->r); return 0; }
static arith_t assignment(int var, int noeval) { union yystype val = yylval; int op = yylex(); arith_t result; char sresult[DIGITS(result) + 1]; if (var != ARITH_VAR) return cond(var, &val, op, noeval); if (op != ARITH_ASS && (op < ARITH_ASS_MIN || op >= ARITH_ASS_MAX)) return cond(var, &val, op, noeval); result = assignment(yylex(), noeval); if (noeval) return result; if (op != ARITH_ASS) result = do_binop(op - 11, arith_lookupvarint(val.name), result); snprintf(sresult, sizeof(sresult), ARITH_FORMAT_STR, result); setvar(val.name, sresult, 0); return result; }