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
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
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
INK INK INK INK INK INK INK INK INK INK INK INK INK INK INK PUK
INK INK INK PUK
INK INK INK INK INK INK INK INK INK INK INK PUK
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

View File

@ -13,18 +13,20 @@ TUK, FUK
char dtape[30000] = {0};//hlava dh
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;
char* dhead = dtape;
inst* phead = ptape;
void run_tukafuk(const char* code) {//
void run_tukafuk(const char* code) {
char current_char;
bool running = false;
size_t i;
//bolo pozadovane zistit, kdd su skoky a teda som ich ulozil
//(tie adresy skokov)
for (i = 0; code[i] != 0; i++) {
for (i = 0; code[i] != 0; i++){
current_char = code[i];
size_t j;
size_t loop;
@ -97,8 +99,9 @@ void run_tukafuk(const char* code) {//
break;
case ']':
for(size_t k=0;k<loopscount;k++){
if(loops[1][k]==i){
if(validRP[k]==i){
*phead = RP;
loops[1][k]=phead;
phead++;
}
}
@ -119,53 +122,90 @@ void run_tukafuk(const char* code) {//
}
if(loop==0){
*phead = LP;
loops[0][loopscount] = phead;
validRP[loopscount++] = j;
phead++;
loops[0][loopscount] = i;
loops[1][loopscount++] = j;
}
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() {
char buff[30000];
FILE *fp;
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);
fread(buff,1,30000,fp);
printf("buffer:\n %s\n",buff);
//printf("buffer:\n %s\n",buff);
run_tukafuk(buff);
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){
case TUK:printf("TUK ");
break;
@ -191,6 +231,6 @@ int main() {
break;
}
}
printf("\n");
*/
return 0;
}

Binary file not shown.