int64_t shift_expr() { int64_t val; val = add_expr(); while(1) { switch(token) { case tk_lshift: NextToken(); val = val << add_expr(); break; case tk_rshift: NextToken(); val = val >> add_expr(); break; default: goto j1; } } j1: return val; }
static void list_expr(void) { number res; start: while (token.type == TOKEN_INTEGER ||token.type == TOKEN_LPARENTH || token.type == TOKEN_EOL || token.type == TOKEN_EOF) { if (token.type == TOKEN_EOL) { get_next_token(); continue; } if (token.type == TOKEN_EOF) { return ; } add_expr(); if (err == SYN_ERR || err == MEM_ERR) { if (err == SYN_ERR) printf("syntax error\n"); if (err == MEM_ERR) printf("memory error\n"); sync_stream(); sp.n = 0; err = 0; goto start; } pop_item(&sp, &res); print_value(res); } printf("syntax error\n"); sync_stream(); goto start; }
static void pr_expr(void) { number val; int rv; rv = mpl_init(&val.value); if (rv != MPL_OK){ err = MEM_ERR; goto out; } switch (token.type) { case TOKEN_LPARENTH: get_next_token(); add_expr(); if (err == SYN_ERR || err == MEM_ERR) { goto out; } if (token.type != TOKEN_RPARENTH) { err = SYN_ERR; goto out; } else { get_next_token(); } goto out; case TOKEN_INTEGER: rv = mpl_copy(&val.value, &token.num.value); val.frac = token.num.frac; if (rv != MPL_OK) goto err; rv = push_item(&sp, &val); if (rv != OK) goto err; get_next_token(); goto out; default: err = SYN_ERR; goto out; } err: err = MEM_ERR; out: return ; }
int ausearch_add_timestamp_item_ex(auparse_state_t *au, const char *op, time_t sec, unsigned milli, unsigned serial, ausearch_rule_t how) { static const struct { unsigned value; const char name[3]; } ts_tab[] = { {EO_VALUE_LT, "<"}, {EO_VALUE_LE, "<="}, {EO_VALUE_GE, ">="}, {EO_VALUE_GT, ">"}, {EO_VALUE_EQ, "="}, }; struct expr *expr; size_t i; unsigned t_op; for (i = 0; i < sizeof(ts_tab) / sizeof(*ts_tab); i++) { if (strcmp(ts_tab[i].name, op) == 0) goto found_op; } goto err_out; found_op: t_op = ts_tab[i].value; if (milli >= 1000) goto err_out; // Make sure how is within range if (how < AUSEARCH_RULE_CLEAR || how > AUSEARCH_RULE_AND) goto err_out; // All pre-checks are done, build a rule expr = expr_create_timestamp_comparison_ex(t_op, sec, milli, serial); if (expr == NULL) return -1; if (add_expr(au, expr, how) != 0) return -1; /* expr is freed by add_expr() */ return 0; err_out: errno = EINVAL; return -1; }
int ausearch_add_regex(auparse_state_t *au, const char *regexp) { struct expr *expr; // Make sure there's an expression if (regexp == NULL) goto err_out; expr = expr_create_regexp_expression(regexp); if (expr == NULL) return -1; if (add_expr(au, expr, AUSEARCH_RULE_AND) != 0) return -1; /* expr is freed by add_expr() */ return 0; err_out: errno = EINVAL; return -1; }
static int ausearch_add_item_internal(auparse_state_t *au, const char *field, const char *op, const char *value, ausearch_rule_t how, unsigned op_eq, unsigned op_ne) { struct expr *expr; // Make sure there's a field if (field == NULL) goto err_out; // Make sure how is within range if (how < AUSEARCH_RULE_CLEAR || how > AUSEARCH_RULE_AND) goto err_out; // All pre-checks are done, build a rule if (strcmp(op, "exists") == 0) expr = expr_create_field_exists(field); else { unsigned t_op; if (strcmp(op, "=") == 0) t_op = op_eq; else if (strcmp(op, "!=") == 0) t_op = op_ne; else goto err_out; if (value == NULL) goto err_out; expr = expr_create_comparison(field, t_op, value); } if (expr == NULL) return -1; if (add_expr(au, expr, how) != 0) return -1; /* expr is freed by add_expr() */ return 0; err_out: errno = EINVAL; return -1; }
int ausearch_add_expression(auparse_state_t *au, const char *expression, char **error, ausearch_rule_t how) { struct expr *expr; if (how < AUSEARCH_RULE_CLEAR || how > AUSEARCH_RULE_AND) goto err_einval; expr = expr_parse(expression, error); if (expr == NULL) { errno = EINVAL; return -1; } if (add_expr(au, expr, how) != 0) goto err; /* expr is freed by add_expr() */ return 0; err_einval: errno = EINVAL; err: *error = NULL; return -1; }
void gcc_rich_location::maybe_add_expr (tree t) { if (EXPR_P (t)) add_expr (t); }
/* expr * : asgExpr * | expr ',' asgExpr */ static void expr(ApexParser *p) { add_expr(p); }
void eval_expr(expr *in, expr *out, symtab *table) { switch (in->type) { case NOTHING: break; case INTEGER: case REAL: case STRING: out->type = in->type; out->val = in->val; return; case INT_VAR: { int n; if (lookup_int(in->val.string, table, &n)) { out->type = INTEGER; out->val.integer = n; return; } else { fprintf(stderr, "undefined integer variable '%s'\n", in->val.string); exit(1); } } break; case REAL_VAR: { double d; if (lookup_real(in->val.string, table, &d)) { out->type = REAL; out->val.real = d; return; } else { fprintf(stderr, "undefined real variable '%s'\n", in->val.string); exit(1); } } break; case STR_VAR: { char *s = (char *)malloc(MAX_LINE); if (lookup_str(in->val.string, table, &s)) { out->type = STRING; out->val.string = s; return; } else { fprintf(stderr, "undefined string variable '%s'\n", in->val.string); exit(1); } } break; } switch (in->op) { case NOTHING: fprintf(stderr, "No operation for non-constant expression\n"); exit(1); case ADD: add_expr(in, out, table); break; case SUB: sub_expr(in, out, table); break; case EXPT: pow_expr(in, out, table); break; case MUL: mul_expr(in, out, table); break; case DIV: div_expr(in, out, table); break; case LT: eval_expr(in->arg1, out->arg1, table); eval_expr(in->arg2, out->arg2, table); out->type = INTEGER; out->val.integer = compare(out->arg1, out->arg2, LT); break; case LE: eval_expr(in->arg1, out->arg1, table); eval_expr(in->arg2, out->arg2, table); out->type = INTEGER; out->val.integer = compare(out->arg1, out->arg2, LE); break; case EQ: eval_expr(in->arg1, out->arg1, table); eval_expr(in->arg2, out->arg2, table); out->type = INTEGER; out->val.integer = compare(out->arg1, out->arg2, EQ); break; case GE: eval_expr(in->arg1, out->arg1, table); eval_expr(in->arg2, out->arg2, table); out->type = INTEGER; out->val.integer = compare(out->arg1, out->arg2, GE); break; case GT: eval_expr(in->arg1, out->arg1, table); eval_expr(in->arg2, out->arg2, table); out->type = INTEGER; out->val.integer = compare(out->arg1, out->arg2, GT); break; case NE: eval_expr(in->arg1, out->arg1, table); eval_expr(in->arg2, out->arg2, table); out->type = INTEGER; out->val.integer = compare(out->arg1, out->arg2, NE); break; /* Numerical functions */ case RAND: { expr arg; eval_expr(in->arg1, &arg, table); out->type = INTEGER; out->val.integer = rand() % arg.val.integer; } break; case SQRT: { expr arg; eval_expr(in->arg1, &arg, table); out->type = REAL; out->val.real = sqrt(arg.type == REAL ? arg.val.real : (double)arg.val.integer); } break; /* Casting */ case CEIL: { expr arg; eval_expr(in->arg1, &arg, table); out->type = INTEGER; out->val.integer = (int)ceil(arg.val.real); } break; case FLOOR: { expr arg; eval_expr(in->arg1, &arg, table); out->type = INTEGER; out->val.integer = (int)floor(arg.val.real); } break; case REAL_CAST: { expr arg; eval_expr(in->arg1, &arg, table); out->type = REAL; out->val.real = (double)arg.val.integer; } break; case ROUND: { expr arg; eval_expr(in->arg1, &arg, table); out->type = INTEGER; out->val.integer = (int)round(arg.val.real); } break; default: fprintf(stderr, "unrecognised operation\n"); exit(1); } }