summaryrefslogtreecommitdiff
path: root/src/bfi.c
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@gmail.com>2022-11-03 01:08:28 +0200
committerRasmus Luha <rasmus.luha@gmail.com>2022-11-03 01:08:28 +0200
commit4bdad2d5c7dec0eb19c418cadb47cc3124092310 (patch)
treec80d9cceb8e10e91daf38657cf64d8ce0bbf3104 /src/bfi.c
parentfcb9ff2b96de6989e9a676e96753b1b1279acf67 (diff)
praks IV doneHEADmaster
Diffstat (limited to 'src/bfi.c')
-rw-r--r--src/bfi.c25
1 files changed, 18 insertions, 7 deletions
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;
}