diff options
author | Rasmus Luha <rasmus.luha@gmail.com> | 2022-11-03 01:08:28 +0200 |
---|---|---|
committer | Rasmus Luha <rasmus.luha@gmail.com> | 2022-11-03 01:08:28 +0200 |
commit | 4bdad2d5c7dec0eb19c418cadb47cc3124092310 (patch) | |
tree | c80d9cceb8e10e91daf38657cf64d8ce0bbf3104 /src/bfi.c | |
parent | fcb9ff2b96de6989e9a676e96753b1b1279acf67 (diff) |
Diffstat (limited to 'src/bfi.c')
-rw-r--r-- | src/bfi.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -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; } |