diff --git a/sk4/program.c b/sk4/program.c index 7a43ff2..228fc78 100644 --- a/sk4/program.c +++ b/sk4/program.c @@ -1,26 +1,133 @@ #include #include #include - -unsigned char tape[30000] = {0}; -unsigned char* ptr = tape; +#include typedef enum { INK, DEK, BREK, GLEK, -BF_NEXT, BF_PREV, -BF_LOOP_START, BF_LOOP_END, -} brainfuck_instruction_t; +PUK, KUK, +LP, RP, +TUK, FUK +}inst; -void interpret(char* input) { +char dtape[30000] = {0};//hlava dh +inst ptape[30000] = {0};//hlava ph +size_t loops[2][15000] = {{0},{0}}; +size_t loopscount=0; +char* dhead = dtape; +inst* phead = ptape; + +void run_tukafuk(const char* code) {// char current_char; + bool running = false; size_t i; - size_t loop; - for (i = 0; input[i] != 0; i++) { - current_char = input[i]; - if (current_char == 'INK') {// > + //bolo pozadovane zistit, kdd su skoky a teda som ich ulozil + //(tie adresy skokov) + for (i = 0; code[i] != 0; i++) { + current_char = code[i]; + size_t j; + size_t loop; + switch(current_char){ + case 'T': + if(code[i+1]=='U') + if(code[i+2]=='K'){ + *phead = TUK; + phead++; + i+=2; + } + break; + case 'I': + if(code[i+1]=='N') + if(code[i+2]=='K'){ + *phead = INK; + phead++; + i+=2; + } + break; + case 'D': + if(code[i+1]=='E') + if(code[i+2]=='K'){ + *phead = DEK; + phead++; + i+=2; + } + break; + case 'B': + if(code[i+1]=='R') + if(code[i+2]=='E') + if(code[i+3] =='K'){ + *phead = BREK; + phead++; + i+=3; + } + break; + case 'G': + if(code[i+1]=='L') + if(code[i+2]=='E') + if(code[i+3] =='K'){ + *phead = GLEK; + phead++; + i+=3; + } + break; + case 'P': + if(code[i+1]=='U') + if(code[i+2]=='K'){ + *phead = PUK; + phead++; + i+=2; + } + break; + case 'K': + if(code[i+1]=='U') + if(code[i+2]=='K'){ + *phead = KUK; + phead++; + i+=2; + } + break; + case 'F': + if(code[i+1]=='U') + if(code[i+2]=='K'){ + *phead = FUK; + phead++; + i+=2; + } + break; + case ']': + for(size_t k=0;k 0){//aby J nepreslo von. + current_char = code[++j];// + if (current_char==0){ + break; + } + if (current_char == ']'){ + loop--; + } else if (current_char == '['){ + loop++; + } + } + if(loop==0){ + *phead = LP; + phead++; + loops[0][loopscount] = i; + loops[1][loopscount++] = j; + } + break; + } + /*if (current_char == 'INK') {//> ++ptr; - } else if (current_char == 'DEK') {// < + } else if (current_char == 'DEK') {//< --ptr; } else if (current_char == 'BREK') {// + ++*ptr; @@ -32,8 +139,8 @@ void interpret(char* input) { *ptr = getchar(); } else if (current_char == '[') {//start loop continue; - } else if (current_char == ']' && *ptr) {//stop loop - loop = 1; + } else if (current_char == ']' && *ptr) {stop loop + loop = 1; while (loop > 0) { current_char = input[--i]; if (current_char == '[') { @@ -41,13 +148,38 @@ void interpret(char* input) { } else if (current_char == ']') { loop++; } - } - } + */ } } - - int main() { - interpret("INK DEK BREK GLEK PUK KUK []");// (",[.[-],]") + run_tukafuk("TUK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK KUK DEK DEK KUK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK KUK KUK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK KUK FUK ");// (",[.[-],]") + printf("Programova Paska: \n"); + for(inst *ptr=ptape;ptr