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
|
||||
17
labubu.c
17
labubu.c
@@ -286,17 +286,22 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
||||
res = lookup(
|
||||
env,
|
||||
ast->data.AST_VARIABLE.name);
|
||||
if (res.found) {
|
||||
if (res.value == NULL) return ast;
|
||||
|
||||
|
||||
if (res.found && res.value != NULL) {
|
||||
if (res.value->tag == AST_VARIABLE)
|
||||
return reduce(res.value, env);
|
||||
else return res.value;
|
||||
}
|
||||
|
||||
return ast;
|
||||
labubu_ast* ast1 = malloc(sizeof (labubu_ast));
|
||||
*ast1 = *ast;
|
||||
return ast1;
|
||||
case AST_APPLICATION:
|
||||
f = reduce(ast->data.AST_APPLICATION.f, env);
|
||||
|
||||
v = reduce(ast->data.AST_APPLICATION.v, env);
|
||||
|
||||
f = reduce(ast->data.AST_APPLICATION.f, env);
|
||||
|
||||
if (f->tag == AST_FUNCTION) {
|
||||
push(env, f->data.AST_FUNCTION.lambda, v);
|
||||
|
||||
@@ -322,7 +327,7 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
||||
int main (void) {
|
||||
labubu_lexer lexer = {
|
||||
.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);
|
||||
tokenize(&lexer);
|
||||
|
||||
Reference in New Issue
Block a user