#include #include #include #include typedef enum { INK, DEK,//Enum je pouzity , BREK, GLEK,//polia 2 rozmerne atd PUK, KUK, LP, RP, TUK, FUK }inst; char dtape[30000] = {0};//hlava dh inst ptape[30000] = {0};//hlava ph size_t validRP[15000]={0}; inst* loops[2][15000] = {{0},{0}};//adresy zatvoriek size_t loopscount=0;//v globalnych premennych su ulozene udaje z pasky char* dhead = dtape;//smerniky inst* phead = ptape; void run_tukafuk(const char* code) { char current_char; bool running = false; size_t i; 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; loops[0][loopscount] = phead; validRP[loopscount++] = j; phead++; } break; } } phead = ptape; for (i = 0; i<30000; i++){ if(running){ switch(*phead){ case INK: //printf("Ink..%c",*dhead); (*dhead)++; //printf("->%c\n",*dhead); break; case DEK: //printf("Dek..%c",*dhead); (*dhead)--; //printf("->%c\n",*dhead); break; case BREK: dhead++; break; case GLEK: dhead--; break; case PUK: //printf("Puk\n"); putchar(*dhead); //printf("\nPukEnd\n"); break; case KUK: printf("Zadaj vstup:\n"); *dhead=getchar(); while(getchar()!='\n'){} //printf("Kukol %c\n",*dhead); break; case FUK: running=false; break; case LP: if(*dhead==0){ for(int j=0;j