Combinatory Logic Program

Standard
Source Code in C

 1:  
 2: #include <stdio.h>
 3: #include <stdlib.h>            //BIBLIOTHIKES
 4: #include <string.h>
 5:  
 6: 
 7: #define MAX 1000   //MEGISTO MEGETHOS PINAKA APOTHIKEYSHS TOY L-OROU.
 8: 
 9:  
 10: const char* valid="()\\->"; //symbola anaparastashs l-oron.
 11: const char* varbles="abcdefghijklmnopqrstuvwxyz"; //metablites.
 12: int mikos; //mikos λ-orou.
 13:  
 14: typedef enum { l_term, var, S, K, I, express} term_type; //Typos l-orou.
 15: term_type type;
 16: 
 17: void elegxos_lorou(char lterm[]);//synartisi gia ton elegxo toy l-orou.
 18: char* l_abs(char* oros1,char* oros2);//synartisi poy ylopoiei tin synartisi abs.
 19: char* comb(char* oros);//synartisi poy ylopoiei tin synartisi comb.
 20: 
 21:  
 22: void main(/*int *argv,char *argc*/) //Enalaktika gia to perasma tou l-orou san parametro. 
 23: {
 24:     char lterm[MAX]; //pinakas apothikeyseis toy l-orou.
 25:     
 26:     //if (argv!=2)
 27:     //{ //Elegxos tis parametrou tou l-orou.
 28:         //printf("DOSTE SOSTA TON λ-ORO");
 29:     //}
 30:     //sscanf("%s",lterm);
 31:     
 32:     printf("Doste ton l-oro\n");
 33:     scanf("%s",&lterm);                    //Diabasma tou l-orou.
 34: 
 35:     elegxos_lorou(lterm); //elegxos tou l-orou.
 36:     printf("Combinatory Logic = %s\n",comb(lterm));
 37:  
 38: }
 39:  
 40: 
 41: void elegxos_lorou(char lterm[]) //synartisi gia ton elegxo toy l-orou.
 42: {
 43:     
 44:     int i=0;
 45:     int vrethikepara,vrethikepark; //metablites gia ton elegxo ton parentheseon
 46: 
 47:     vrethikepara=vrethikepark=0;//synolo parenteseon aristeron-deksion
 48:     mikos=0; //mikos λ-orou.
 49:     
 50: 
 51:  
 52:     for(i=0;i<MAX;i++)      //eyresi mikous tou l-orou.
 53:     {
 54:         if(lterm[i]==0)
 55:         {
 56:             i=MAX;
 57:         }
 58:         mikos+=1;
 59:     }
 60:     mikos--;
 61:     
 62:     //elegxos λ-oron.
 63:     for(i=0;i<mikos;i++)
 64:     {
 65:         if(strchr(varbles,lterm[i]) || strchr(valid,lterm[i]))
 66:         {
 67:             goto a;
 68:         }
 69:         else
 70:         {
 71:             printf("Doste sosta to l-oro\n");
 72:             exit(0);
 73:         }
 74: 
 75: a:;        if(lterm[i]=='\\')
 76:         {
 77:             if(lterm[i+2]!='-')
 78:             {
 79:                 printf("Doste sosta to l-oro\n");
 80:                 exit(0);
 81:             }
 82:         }
 83:         if(lterm[i]=='-')
 84:         {
 85:             if(lterm[i+1]!='>')
 86:             {
 87:                 printf("Doste sosta to l-oro\n");
 88:                 exit(0);
 89:             }
 90:         }
 91:  
 92:         //metrima parentheseon.
 93:         if(lterm[i]=='(')
 94:         {
 95:             vrethikepara+=1;
 96:         }
 97:         if(lterm[i]==')')
 98:         {
 99:             vrethikepark+=1;
 100:         }
 101:     }
 102: 
 103:     //elegxos parentheseon.
 104:     if(vrethikepara!=vrethikepark)
 105:     {
 106:         printf("Lathos Parentheseis\n");
 107:         exit(0);
 108:     }
 109:     
 110:     //eyresi toy typou tou l-orou.
 111:     if(mikos==1 && strchr(varbles,lterm[0]))
 112:     {
 113:         type=var;
 114:     }
 115:     else
 116:     {
 117:         type=express;
 118:         for(i=0;i<mikos;i++)
 119:         {
 120:             if(lterm[i]=='\\')
 121:             {
 122:                 type=l_term;
 123:             }
 124:         }
 125:     }
 126: 
 127:     //typosi toy typou tou l-orou.
 128:     switch(type)
 129:     {
 130:         case 0:
 131:             printf("O oros einai l_oros\n");
 132:             break;
 133:         case 1:
 134:             printf("O oros einai metabliti\n");
 135:             printf("Dose sosta enan l-oro\n");
 136:             exit(0);
 137:         case 5:
 138:             printf("O oros einai ekfrasi\n");
 139:             printf("Dose sosta enan l-oro\n");
 140:             exit(0);
 141:         default:
 142:             break;
 143:     }
 144: }
 145:  
 146: 
 147:  
 148: 
 149:  
 150: 
 151: char* l_abs(char* oros1,char *oros2) //synartisi ylopoihshs tis synartisis abs
 152: {
 153:     int i,j,vrethikepara,vrethikepard;
 154:     char buffer[1000],buffer1[1000],buffer2[1000],buffer3[1000];
 155:     char noros2[1000],noros3[1000];
 156:     char *final,*final1,*final2;
 157:     
 158:     /////////////////////////////////////////////////////////////////////////////////////////////
 159:     if(strcmp(oros1,oros2)==0 && oros2[1]=='\0') //abs(x,x)=I
 160:     {
 161:         return ("I");
 162:     }
 163:  
 164:     //////////////////////////////////////////////////////////////////////////////////////////////
 165:     if(strcmp(oros1,oros2)!=0 && oros2[0]!='(' && oros2[1]=='\0' && strchr(varbles,oros2[0]))
 166:     {
 167:         strcat(oros2,"K");
 168:         buffer[0]=oros2[0];
 169:         oros2[0]=oros2[1];
 170:         oros2[1]=buffer[0];
 171:                                             //abs(x,y)=(Ky)
 172:         buffer[0]=oros2[0];
 173:         oros2[0]='(';
 174:         oros2[2]=oros2[1];
 175:         oros2[1]=buffer[0];
 176:         oros2[3]=')';
 177:         oros2[4]='\0';
 178:         return(oros2);
 179:     }
 180: 
 181:     ///////////////////////////////////////////////////////////////////////////////////////////////
 182:     if((oros2[0]=='K'||oros2[0]=='S'||oros2[0]=='I') && oros2[1]=='\0')
 183:     {
 184:         strcat(oros2,"K");
 185:         buffer[0]=oros2[0];
 186:         oros2[0]=oros2[1];
 187:         oros2[1]=buffer[0];
 188:                                         //abs(x,c)=(Kc)    , c=K,S,I
 189:         buffer[0]=oros2[0];
 190:         oros2[0]='(';
 191:         oros2[2]=oros2[1];
 192:         oros2[1]=buffer[0];
 193:         oros2[3]=')';
 194:         oros2[4]='\0';
 195:         return(oros2);
 196:     }
 197:     
 198:     /////////////////////////////////////////////////////////////////////////////////////////////////
 199:  
 200:     if(oros2[1]!='\0')
 201:     {
 202:         i=0;
 203:         vrethikepara=vrethikepard=0;
 204:         while(oros2[i]!='\0')
 205:         {
 206:             if(oros2[i]=='(')
 207:             {
 208:                 vrethikepara+=1;
 209:             }
 210:             if(oros2[i]==')')
 211:             {
 212:                 vrethikepard+=1;
 213:             }
 214: 
 215:             if((vrethikepara==vrethikepard) && oros2[i+1]=='\0')//////////////////////////////////////
 216:             {
 217:                 i=0;
 218:                 while(oros2[i+2]!='\0')
 219:                 {
 220:                     noros2[i]=oros2[i+1];
 221:                     i++;
 222:                 }
 223:                 noros2[i]='\0';
 224: 
 225:                 final=l_abs(oros1,noros2);
 226:                                                     //abs(x,(E))=(abs(x,E))
 227:                 i=0;
 228:                 buffer[0]='(';
 229:                 while(final[i]!='\0')
 230:                 {
 231:                     buffer[i+1]=final[i];
 232:                     i++;
 233:                 }
 234:                 buffer[i+1]=')';
 235:                 buffer[i+2]='\0';
 236:                 return(buffer);    /////////////////////////////////////////////////////////////////////
 237:             }
 238: 
 239:             noros2[i]=oros2[i];
 240:             if(vrethikepara==vrethikepard)
 241:             {
 242:                 noros2[i+1]='\0';
 243:                 goto b;
 244:             }
 245:             i++;
 246:         }
 247:  
 248: b:;        j=0;
 249:         i++;
 250:         while(oros2[i]!='\0')
 251:         {
 252:             noros3[j]=oros2[i];
 253:             i++;
 254:             j++;
 255:         }
 256:         noros3[j]='\0';
 257:  
 258: 
 259:         final1=l_abs(oros1,noros2);
 260:         i=0;
 261:             while(final1[i]!='\0')
 262:             {
 263:                 buffer2[i]=final1[i];
 264:                 i++;
 265:             }
 266:             buffer2[i]='\0';
 267:         
 268:         final2=l_abs(oros1,noros3);
 269:  
 270:         buffer3[0]='S';
 271:         buffer3[1]='\0';
 272:                                                     //abs(x,E1E2)=((S abs(x,E1))abs(x,E2))
 273:         strcat(buffer3,buffer2);
 274:         //
 275:         i=0;
 276:         buffer1[0]='(';
 277:         while(buffer3[i]!='\0')
 278:         {
 279:             buffer1[i+1]=buffer3[i];
 280:             i++;
 281:         }
 282:         buffer1[i+1]=')';
 283:         buffer1[i+2]='\0';
 284:         //
 285:         strcat(buffer1,final2);
 286: 
 287:         i=0;
 288:         buffer[0]='(';
 289:         while(buffer1[i]!='\0')
 290:         {
 291:             buffer[i+1]=buffer1[i];
 292:             i++;
 293:         }
 294:         buffer[i+1]=')';
 295:         buffer[i+2]='\0';
 296: 
 297:         return(buffer);
 298:     ///////////////////////////////////////////////////////////////////////////////////////
 299:     }
 300: 
 301:     
 302:     return("Lathos ston l-oro");
 303:     
 304: }
 305:  
 306: 
 307:  
 308: char* comb(char* oros)  //Synartisi ylopoihshs tis synartisis comb.
 309: {
 310:     int i,j,vrethikepara,vrethikepard;
 311:     char *final1,*final2;
 312:     char noros2[1000],noros3[1000],noros4[1000];
 313:     char buffer[1000],buffer1[1000];
 314: 
 315:     ///////////////////////////////////////////////////////////////////////////////////////
 316:     if (strchr(varbles,oros[0]) && oros[1]=='\0')
 317:     {
 318:         return oros;                        //comb(x)=x.
 319:     }
 320: 
 321:     ///////////////////////////////////////////////////////////////////////////////////////
 322:     if(oros[0]=='(' && oros[1]!='\\' )
 323:     {
 324:         i=1;
 325:         j=vrethikepara=vrethikepard=0;
 326:         while((oros[i]!=')') || (oros[i+1]!='\0'))
 327:         {
 328:             if(oros[i]=='(')
 329:             {
 330:                 vrethikepara+=1;
 331:             }
 332:             if(oros[i]==')')
 333:             {
 334:                 vrethikepard+=1;
 335:             }
 336:             noros2[j]=oros[i];
 337:             if(vrethikepara==vrethikepard)
 338:             {
 339:                 noros2[j+1]='\0';
 340:                 goto d;
 341:             }
 342:             i++;
 343:             j++;
 344:         }                                            //comb((E1E2))=(comb(E1) comb(E2))
 345: d:;        j=0;
 346:         while((oros[i+1]!=')') && (oros[i+2]!='\0'))
 347:         {
 348:             noros3[j]=oros[i+1];
 349:             i++;
 350:             j++;
 351:         }
 352:         noros3[j]='\0';
 353:         
 354:         final1=comb(noros2);
 355:         i=0;
 356:             while(final1[i]!='\0')
 357:             {
 358:                 buffer1[i]=final1[i];
 359:                 i++;
 360:             }
 361:             buffer1[i]='\0';
 362:         final2=comb(noros3);
 363:         
 364:         strcat(buffer1,final2);
 365:  
 366:         i=0;
 367:         buffer[0]='(';
 368:         while(buffer1[i]!='\0')
 369:         {
 370:             buffer[i+1]=buffer1[i];
 371:             i++;
 372:         }
 373:         buffer[i+1]=')';
 374:         buffer[i+2]='\0';
 375:         
 376:         return(buffer);
 377:     }
 378:     //////////////////////////////////////////////////////////////////////////////////////////
 379:  
 380:     if(oros[0]=='(' && oros[1]=='\\' )
 381:     {
 382:         i=5;
 383:         j=0;
 384:         while(oros[i+1]!='\0')
 385:         {
 386:             noros2[j]=oros[i];
 387:             i++;
 388:             j++;
 389:         }
 390:         noros2[j]='\0';
 391:  
 392:         noros3[0]=oros[2];
 393:         noros3[1]='\0';
 394:                                                         //comb((lx.E))=(abs(x,comb(E)))
 395:         final1=comb(noros2);
 396:         i=0;
 397:         while(final1[i]!='\0')
 398:         {
 399:             noros4[i]=final1[i];
 400:             i++;
 401:         }
 402:         noros4[i]='\0';
 403:         final2=l_abs(noros3,noros4);
 404: 
 405:         i=0;
 406:         buffer[0]='(';
 407:         while(final2[i]!='\0')
 408:         {
 409:             buffer[i+1]=final2[i];
 410:             i++;
 411:         }
 412:         buffer[i+1]=')';
 413:         buffer[i+2]='\0';
 414: 
 415:         return(buffer);
 416:     }
 417:     ////////////////////////////////////////////////////////////////////////////////////////
 418:     return("Lathos ston l-oro");
 419: }
yeezy boost 350 ua yeezytrainer yeezy boost 350 ua yeezytrainer yeezytrainer yeezy boost 350 ua yeezy boost 350 ua yeezy shoes yeezy shoes yeezy boost online

yeezy 350 boost for sale yeezy boost online yeezy shoes yeezy 350 boost for sale yeezy boost online yeezy shoes yeezy 350 boost for sale yeezy boost online yeezy shoes yeezy 350 boost for sale yeezy boost online yeezy shoes