fixed bug related to variables
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
labubu
|
||||||
|
a.out
|
||||||
21
labubu.c
21
labubu.c
@@ -286,17 +286,22 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
|||||||
res = lookup(
|
res = lookup(
|
||||||
env,
|
env,
|
||||||
ast->data.AST_VARIABLE.name);
|
ast->data.AST_VARIABLE.name);
|
||||||
if (res.found) {
|
|
||||||
if (res.value == NULL) return ast;
|
|
||||||
return reduce(res.value, env);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ast;
|
|
||||||
|
if (res.found && res.value != NULL) {
|
||||||
|
if (res.value->tag == AST_VARIABLE)
|
||||||
|
return reduce(res.value, env);
|
||||||
|
else return res.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
labubu_ast* ast1 = malloc(sizeof (labubu_ast));
|
||||||
|
*ast1 = *ast;
|
||||||
|
return ast1;
|
||||||
case AST_APPLICATION:
|
case AST_APPLICATION:
|
||||||
f = reduce(ast->data.AST_APPLICATION.f, env);
|
|
||||||
|
|
||||||
v = reduce(ast->data.AST_APPLICATION.v, env);
|
v = reduce(ast->data.AST_APPLICATION.v, env);
|
||||||
|
|
||||||
|
f = reduce(ast->data.AST_APPLICATION.f, env);
|
||||||
|
|
||||||
if (f->tag == AST_FUNCTION) {
|
if (f->tag == AST_FUNCTION) {
|
||||||
push(env, f->data.AST_FUNCTION.lambda, v);
|
push(env, f->data.AST_FUNCTION.lambda, v);
|
||||||
|
|
||||||
@@ -322,7 +327,7 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
|||||||
int main (void) {
|
int main (void) {
|
||||||
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.x) \\x.\\y.x)"
|
.rest = "((\\a.\\b.((a b) \\x.\\y.y) \\x.\\y.y) \\x.\\y.x)"
|
||||||
};
|
};
|
||||||
printf("%s = ", lexer.rest);
|
printf("%s = ", lexer.rest);
|
||||||
tokenize(&lexer);
|
tokenize(&lexer);
|
||||||
|
|||||||
Reference in New Issue
Block a user