SemVal *p_addition(SemVal *lval, SemVal *rval) { register ExprType type; if (p_testBinOp(op_add, lval, rval)) return p_nullFrame(lval, rval); /* test for correct types */ p_bool2int(lval); /* convert pending booleans */ p_bool2int(rval); if (p_conflict(lval, rval, op_add)) /* test type p_conflict */ return p_nullFrame(lval, rval); type = lval->type; /* keep type for later */ if ((type & rval->type & (unsigned)~e_typeMask) == e_const) { if (test_type(lval, e_int)) lval->evalue += rval->evalue; else if (test_type(lval, e_str)) p_catStrings(lval, rval); /* create (cat) new string */ } else { p_binOp(lval, rval, op_add); set_type(lval, (type & e_typeMask) | e_stack); } return lval; /* return new expression */ }
SemVal *p_subtract(SemVal *lval, SemVal *rval) { register ExprType type; if (p_testBinOp(op_sub, lval, rval)) return (lval); /* test for correct types */ p_bool2int(lval); /* convert pending booleans */ p_bool2int(rval); if (p_conflict(lval, rval, op_sub)) /* test type p_conflict */ return(lval); type = lval->type; /* remember the type */ if ((lval->type & rval->type & (size_t)~e_typeMask) == e_const) lval->evalue -= rval->evalue; else { p_binOp(lval, rval, op_sub); set_type(lval, type & (e_typeMask | e_stack)); } return (lval); /* return new expression */ }
SemVal *p_young(SemVal *lval, SemVal *rval) { msg("start"); if (p_testBinOp(op_younger, lval, rval)) return p_nullFrame(lval, rval); /* test for correct types */ p_expr2stack(lval); /* convert to code */ p_expr2stack(rval); p_binOp(lval, rval, op_younger); return lval; /* return new expression */ }
SemVal *p_multiply(SemVal *lval, SemVal *rval) { if (p_testBinOp(op_mul, lval, rval)) return p_nullFrame(lval, rval); /* test for correct types */ p_bool2int(lval); /* convert pending booleans */ p_bool2int(rval); if (p_conflict(lval, rval, op_mul)) /* test type p_conflict */ return p_nullFrame(lval, rval); if ((lval->type & rval->type & (unsigned)~e_typeMask) == e_const) lval->evalue *= rval->evalue; else p_binOp(lval, rval, op_mul); return lval; /* return new expression */ }