basically done
This commit is contained in:
16
labubu.c
16
labubu.c
@@ -289,7 +289,8 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
|||||||
|
|
||||||
|
|
||||||
if (res.found && res.value != NULL) {
|
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);
|
return reduce(res.value, env);
|
||||||
else return res.value;
|
else return res.value;
|
||||||
}
|
}
|
||||||
@@ -324,10 +325,10 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void) {
|
void read (char* content) {
|
||||||
labubu_lexer lexer = {
|
labubu_lexer lexer = {
|
||||||
.tokens = malloc(1024 * sizeof (labubu_token)),
|
.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);
|
printf("%s = ", lexer.rest);
|
||||||
tokenize(&lexer);
|
tokenize(&lexer);
|
||||||
@@ -340,3 +341,12 @@ int main (void) {
|
|||||||
ast_print(reduced);
|
ast_print(reduced);
|
||||||
printf("\n");
|
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))))");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user