add inverse function

This commit is contained in:
Christian Barthel 2019-06-29 12:30:06 +02:00
parent 6440eeec77
commit 6f1ba0333f
1 changed files with 19 additions and 0 deletions

View File

@ -274,6 +274,23 @@ eval_add(struct ast *a, struct env *e)
NULL));
}
/* inv <ausdruck::NUM> */
struct ast *
eval_inv(struct ast *a, struct env *e)
{
assert(a != NULL &&
a->next != NULL);
struct ast *op = eval(a->next, e);
assert(op != NULL &&
op->type == AST_TOK &&
op->v.token->type == NUM);
return make_ast(AST_TOK,
make_token(NUM,
0 -
op->v.token->v.num,
NULL));
}
struct ast *
eval_sym(struct ast *a, struct env *e)
{
@ -281,6 +298,8 @@ eval_sym(struct ast *a, struct env *e)
return eval_def(a, e);
else if (strcmp(a->v.token->v.str, "lm") == 0) {
} else if (strcmp(a->v.token->v.str, "if") == 0) {
} else if (strcmp(a->v.token->v.str, "inv") == 0) {
return eval_inv(a, e);
} else if (strcmp(a->v.token->v.str, "add") == 0) {
return eval_add(a, e);
} else if (strcmp(a->v.token->v.str, "q") == 0) {