This commit is contained in:
Radovan Kofira 2021-01-09 20:33:08 +01:00
parent 045c3b8e85
commit 2089ceee18
3 changed files with 91 additions and 43 deletions

View File

@ -1,7 +1,15 @@
TUK 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 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 PUK
DEK DEK KUK INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK PUK
DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK KUK INK INK INK PUK
KUK INK INK INK INK INK INK INK INK INK INK INK PUK
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 BREK
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 PUK
GLEK
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 PUK
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 PUK
DEK DEK DEK DEK DEK DEK DEK DEK DEK PUK 102
INK INK INK PUK 105
INK INK INK INK INK INK INK INK INK PUK 114
DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK DEK PUK 97
FUK FUK

View File

@ -13,12 +13,14 @@ TUK, FUK
char dtape[30000] = {0};//hlava dh char dtape[30000] = {0};//hlava dh
inst ptape[30000] = {0};//hlava ph inst ptape[30000] = {0};//hlava ph
size_t loops[2][15000] = {{0},{0}}; size_t validRP[15000]={0};
inst* loops[2][15000] = {{0},{0}};//adresy zatvoriek
size_t loopscount=0; size_t loopscount=0;
char* dhead = dtape; char* dhead = dtape;
inst* phead = ptape; inst* phead = ptape;
void run_tukafuk(const char* code) {// void run_tukafuk(const char* code) {
char current_char; char current_char;
bool running = false; bool running = false;
size_t i; size_t i;
@ -97,8 +99,9 @@ void run_tukafuk(const char* code) {//
break; break;
case ']': case ']':
for(size_t k=0;k<loopscount;k++){ for(size_t k=0;k<loopscount;k++){
if(loops[1][k]==i){ if(validRP[k]==i){
*phead = RP; *phead = RP;
loops[1][k]=phead;
phead++; phead++;
} }
} }
@ -119,53 +122,90 @@ void run_tukafuk(const char* code) {//
} }
if(loop==0){ if(loop==0){
*phead = LP; *phead = LP;
loops[0][loopscount] = phead;
validRP[loopscount++] = j;
phead++; phead++;
loops[0][loopscount] = i;
loops[1][loopscount++] = j;
} }
break; break;
} }
/*if (current_char == 'INK') {//>
++ptr;
} else if (current_char == 'DEK') {//<
--ptr;
} else if (current_char == 'BREK') {// +
++*ptr;
} else if (current_char == 'GLEK') {// -
--*ptr;
} else if (current_char == 'PUK' ) {// .
putchar(*ptr);
} else if (current_char == 'KUK') {// ,
*ptr = getchar();
} else if (current_char == '[') {//start loop
continue;
} else if (current_char == ']' && *ptr) {stop loop
loop = 1;
while (loop > 0) {
current_char = input[--i];
if (current_char == '[') {
loop--;
} else if (current_char == ']') {
loop++;
} }
*/ phead = ptape;
for (i = 0; i<30000; i++){
if(running){
switch(*phead){
case INK:
(*dhead)++;
break;
case DEK:
(*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();
//printf("Kukol %c\n",*dhead);
break;
case FUK:
running=false;
break;
case LP:
if(*dhead==0){
for(int j=0;j<loopscount;j++){
if(loops[0][j]==phead){
phead=loops[1][j];
break;
} }
} }
}
break;
case RP:
if(*dhead!=0){
for(int j=0;j<loopscount;j++){
if(loops[1][j]==phead){
phead=loops[0][j];
break;
}
}
}
}
if(!running)
break;
}
else{
if(*phead==TUK)
running=true;
}
phead++;
}
printf(" \n");
}
int main() { int main() {
char buff[30000]; char buff[30000];
FILE *fp; FILE *fp;
fp = fopen("kod.txt","r"); fp = fopen("kod.txt","r");
//memset(buff,0,sizeof(buff));
size_t fr = fread(buff,1,30000,fp);
buff[fr]=0;
memset(buff,0,sizeof(buff)); //printf("buffer:\n %s\n",buff);
printf("buffer:\n %s\n",buff);
fread(buff,1,30000,fp);
printf("buffer:\n %s\n",buff);
run_tukafuk(buff); run_tukafuk(buff);
fclose(fp); fclose(fp);
printf("Programova Paska: \n"); /*printf("Programova Paska: \n");
for(inst *ptr=ptape;ptr<phead;ptr++){ for(inst *ptr=ptape;ptr<=phead;ptr++){
switch (*ptr){ switch (*ptr){
case TUK:printf("TUK "); case TUK:printf("TUK ");
break; break;
@ -191,6 +231,6 @@ int main() {
break; break;
} }
} }
printf("\n"); */
return 0; return 0;
} }

Binary file not shown.