From b673f99433798c1d0fb35fda3e19dcadff9b4a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Tue, 11 Jun 2024 02:53:49 +0500 Subject: [PATCH] Fix multiple statements --- src/compile.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/compile.c b/src/compile.c index eefbaf1..bfd8828 100644 --- a/src/compile.c +++ b/src/compile.c @@ -135,37 +135,45 @@ char* compile(tSyntaxElement* syntaxtree) { char* result = calloc(1,sizeof(char)); - if (se_istraversable(syntaxtree)) { + while (1) { - if (syntaxtree->content.syntax->type == TOKEN) { + if (se_istraversable(syntaxtree)) { - tSyntaxElement* token = syntaxtree->content.syntax; + if (syntaxtree->content.syntax->type == TOKEN) { - if (strcmp(token->content.string, "def") == 0) { - } else + tSyntaxElement* token = syntaxtree->content.syntax; - if (strcmp(token->content.string, "set") == 0) { + if (strcmp(token->content.string, "def") == 0) { + } else - compile_enter_tag(&result); + if (strcmp(token->content.string, "set") == 0) { - string_append(&result, "set "); - string_append(&result,token->next->content.string); - string_append(&result,"="); - string_append(&result,compile_expression(token->next->next)); + compile_enter_tag(&result); - compile_exit_tag(&result); + string_append(&result, "set "); + string_append(&result,token->next->content.string); + string_append(&result,"="); + string_append(&result,compile_expression(token->next->next)); - } else + compile_exit_tag(&result); - if (strcmp(token->content.string, "print") == 0) { + } else - string_append(&result, "{{"); - string_append(&result,compile_expression(token->next)); - string_append(&result, "}}"); + if (strcmp(token->content.string, "print") == 0) { + + string_append(&result, "{{"); + string_append(&result,compile_expression(token->next)); + string_append(&result, "}}"); + + } } } + + if (syntaxtree->next != NULL) + syntaxtree = syntaxtree->next; + else break; }