/* ** 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); }
bool forward_dir(void) { bool ok = true; // ok &= abs_op(); ok &= acos_op(); ok &= acosh_op(); ok &= asin_op(); ok &= asinh_op(); ok &= atan_op(); ok &= atanh_op(); ok &= addpv_op(); ok &= addvv_op(); ok &= cexp_op(); ok &= cosh_op(); ok &= cos_op(); ok &= csum_op(); ok &= dis_op(); ok &= divpv_op(); ok &= divvp_op(); ok &= divvv_op(); ok &= exp_op(); ok &= load_op(); ok &= log_op(); ok &= mulpv_op(); ok &= par_op(); ok &= powpv_op(); ok &= powvp_op(); ok &= powvv_op(); ok &= sign_op(); ok &= sin_op(); ok &= sinh_op(); ok &= subpv_op(); ok &= subvp_op(); ok &= subvv_op(); ok &= sqrt_op(); ok &= tan_op(); ok &= tanh_op(); ok &= usr_op(); // return ok; }
static sql_rel * psm_analyze(mvc *sql, dlist *qname, dlist *columns, symbol *sample ) { exp_kind ek = {type_value, card_value, FALSE}; sql_exp *sample_exp = NULL, *call; char *sname = NULL, *tname = NULL; list *tl = sa_list(sql->sa); list *exps = sa_list(sql->sa), *analyze_calls = sa_list(sql->sa); sql_subfunc *f = NULL; if (sample) { sql_subtype *tpe = sql_bind_localtype("lng"); sample_exp = rel_value_exp( sql, NULL, sample, 0, ek); if (sample_exp) sample_exp = rel_check_type(sql, tpe, sample_exp, type_cast); } if (qname) { if (qname->h->next) sname = qname_schema(qname); else sname = qname_table(qname); if (!sname) sname = cur_schema(sql)->base.name; if (qname->h->next) tname = qname_table(qname); } /* call analyze( [schema, [ table ]], opt_sample_size ) */ if (sname) { sql_exp *sname_exp = exp_atom_clob(sql->sa, sname); append(exps, sname_exp); append(tl, exp_subtype(sname_exp)); } if (tname) { sql_exp *tname_exp = exp_atom_clob(sql->sa, tname); append(exps, tname_exp); append(tl, exp_subtype(tname_exp)); if (columns) append(tl, exp_subtype(tname_exp)); } if (!columns) { if (sample_exp) { append(exps, sample_exp); append(tl, exp_subtype(sample_exp)); } f = sql_bind_func_(sql->sa, mvc_bind_schema(sql, "sys"), "analyze", tl, F_PROC); if (!f) return sql_error(sql, 01, "Analyze procedure missing"); call = exp_op(sql->sa, exps, f); append(analyze_calls, call); } else { dnode *n; if (sample_exp) append(tl, exp_subtype(sample_exp)); f = sql_bind_func_(sql->sa, mvc_bind_schema(sql, "sys"), "analyze", tl, F_PROC); if (!f) return sql_error(sql, 01, "Analyze procedure missing"); for( n = columns->h; n; n = n->next) { char *cname = n->data.sval; list *nexps = list_dup(exps, NULL); sql_exp *cname_exp = exp_atom_clob(sql->sa, cname); append(nexps, cname_exp); if (sample_exp) append(nexps, sample_exp); /* call analyze( sname, tname, cname, opt_sample_size ) */ call = exp_op(sql->sa, nexps, f); append(analyze_calls, call); } } return rel_psm_block(sql->sa, analyze_calls); }
sql_exp * exp_copy( sql_allocator *sa, sql_exp * e) { sql_exp *l, *r, *r2, *ne = NULL; switch(e->type){ case e_column: ne = exp_column(sa, e->l, e->r, exp_subtype(e), e->card, has_nil(e), is_intern(e)); ne->flag = e->flag; break; case e_cmp: if (e->flag == cmp_or) { list *l = exps_copy(sa, e->l); list *r = exps_copy(sa, e->r); if (l && r) ne = exp_or(sa, l,r); } else if (e->flag == cmp_in || e->flag == cmp_notin || get_cmp(e) == cmp_filter) { sql_exp *l = exp_copy(sa, e->l); list *r = exps_copy(sa, e->r); if (l && r) { if (get_cmp(e) == cmp_filter) ne = exp_filter(sa, l, r, e->f, is_anti(e)); else ne = exp_in(sa, l, r, e->flag); } } else { l = exp_copy(sa, e->l); r = exp_copy(sa, e->r); if (e->f) { r2 = exp_copy(sa, e->f); if (l && r && r2) ne = exp_compare2(sa, l, r, r2, e->flag); } else if (l && r) { ne = exp_compare(sa, l, r, e->flag); } } break; case e_convert: l = exp_copy(sa, e->l); if (l) ne = exp_convert(sa, l, exp_fromtype(e), exp_totype(e)); break; case e_aggr: case e_func: { list *l = e->l, *nl = NULL; if (!l) { return e; } else { nl = exps_copy(sa, l); if (!nl) return NULL; } if (e->type == e_func) ne = exp_op(sa, nl, e->f); else ne = exp_aggr(sa, nl, e->f, need_distinct(e), need_no_nil(e), e->card, has_nil(e)); break; } case e_atom: if (e->l) ne = exp_atom(sa, e->l); else if (!e->r) ne = exp_atom_ref(sa, e->flag, &e->tpe); else ne = exp_param(sa, e->r, &e->tpe, e->flag); break; case e_psm: if (e->flag == PSM_SET) ne = exp_set(sa, e->name, exp_copy(sa, e->l), GET_PSM_LEVEL(e->flag)); break; } if (ne && e->p) ne->p = prop_copy(sa, e->p); if (e->name) exp_setname(sa, ne, exp_find_rel_name(e), exp_name(e)); return ne; }