From 4bdad2d5c7dec0eb19c418cadb47cc3124092310 Mon Sep 17 00:00:00 2001 From: Rasmus Luha Date: Thu, 3 Nov 2022 01:08:28 +0200 Subject: praks IV done --- src/bfi.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/bfi.c') diff --git a/src/bfi.c b/src/bfi.c index cc13b11..03b32c1 100644 --- a/src/bfi.c +++ b/src/bfi.c @@ -11,6 +11,9 @@ #endif void intepret(char *program){ + + struct stack_st stack= { .len = 0, .size = 0, .arr = NULL}; + int i = 0; int length = 0; while (program[i++] != '\0') @@ -18,8 +21,6 @@ void intepret(char *program){ i = 0; while (i < length){ - //printf("i = %d\n",i); - //printf("%c\n", program[i]); switch(program[i]) { @@ -69,9 +70,14 @@ void intepret(char *program){ case BF_START_LOOP: { - stackPush(i); + stackPush(&stack, i); int memVal = mem_get(); + //printf("StartLoop! i = %d\n",i); + //printf("memVal: %d\n", mem_get()); + //printf("stackVal: %d\n", stackPeek(&stack)); + //printf("%c\n\n", program[i]); + //Skiping loop if (memVal == 0){ int helpCounter = 1; @@ -82,19 +88,24 @@ void intepret(char *program){ if (program[i] == ']') helpCounter--; } - stackPop(); + stackPop(&stack); } break; } case BF_END_LOOP: { + //printf("Endloop! i = %d\n",i); + //printf("memVal: %d\n", mem_get()); + //printf("stackVal: %d\n", stackPeek(&stack)); + //printf("%c\n\n", program[i]); + if (mem_get() != 0){ - i = stackPop(); - stackPush(i); + i = stackPop(&stack); + stackPush(&stack, i); } else - stackPop(); + stackPop(&stack); break; } -- cgit v1.2.3