From e718421f1712ae5172d4ed855a40ec761695febc Mon Sep 17 00:00:00 2001 From: Christian Barthel Date: Sun, 30 Jun 2019 22:44:14 +0200 Subject: [PATCH] lower than --- tokenize.l | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tokenize.l b/tokenize.l index 0e23c61..af83d0c 100644 --- a/tokenize.l +++ b/tokenize.l @@ -306,6 +306,31 @@ eval_add(struct ast *a, struct env *e) NULL)); } +/* (lt ) -> BOOL*/ +struct ast * +eval_lt(struct ast *a, struct env *e) +{ + assert (a != NULL && + a->next != NULL && + a->next->next != NULL && + a->next->next->next == NULL); + + struct ast *op1 = eval(a->next, e); + struct ast *op2 = eval(a->next->next, e); + + assert (op1 != NULL && + op1->type == AST_TOK && + op1->v.token->type == NUM && + op2 != NULL && + op2->type == AST_TOK && + op2->v.token->type == NUM); + return make_ast(AST_TOK, + make_token(BOOL, + op1->v.token->v.num < + op2->v.token->v.num, + NULL)); +} + /* (inv ) -> NUM */ struct ast * eval_inv(struct ast *a, struct env *e) @@ -336,6 +361,8 @@ eval_sym(struct ast *a, struct env *e) 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, "lt") == 0) { + return eval_lt(a, e); } else if (strcmp(a->v.token->v.str, "nand") == 0) { return eval_nand(a, e); } else if (strcmp(a->v.token->v.str, "q") == 0) {