From a86ccba42787b9a268fb6b1f71a32909daa7bf09 Mon Sep 17 00:00:00 2001 From: bunny Date: Sat, 4 Oct 2025 22:19:51 +0100 Subject: [PATCH] basically done --- labubu.c | 16 +++++++++++++--- list.ml | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 list.ml diff --git a/labubu.c b/labubu.c index 4b885bb..5138241 100644 --- a/labubu.c +++ b/labubu.c @@ -289,7 +289,8 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) { if (res.found && res.value != NULL) { - if (res.value->tag == AST_VARIABLE) + if (res.value->tag == AST_VARIABLE && + strcmp(res.value->data.AST_VARIABLE.name, ast->data.AST_VARIABLE.name) != 0) return reduce(res.value, env); else return res.value; } @@ -324,10 +325,10 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) { return NULL; } -int main (void) { +void read (char* content) { labubu_lexer lexer = { .tokens = malloc(1024 * sizeof (labubu_token)), - .rest = "((\\a.\\b.((a b) \\x.\\y.y) \\x.\\y.y) \\x.\\y.x)" + .rest = content }; printf("%s = ", lexer.rest); tokenize(&lexer); @@ -340,3 +341,12 @@ int main (void) { ast_print(reduced); printf("\n"); } + +int main (void) { + read("x"); + read("\\x.x"); + read("(\\x.x x)"); + read("(\\x.x \\y.y)"); + read("((\\a.\\b.((a b) \\x.\\y.y) \\x.\\y.y) \\x.\\y.x)"); + read("(\\n.\\f.\\x.(f ((n f) x)) \\f.\\x.(f (f (f x))))"); +} diff --git a/list.ml b/list.ml new file mode 100644 index 0000000..6e68ba2 --- /dev/null +++ b/list.ml @@ -0,0 +1,2 @@ +type 'a my_list = Cons of 'a * 'a my_list + | Nil