• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

System Programming

Macro Processor Pass Two in C Language

May 4, 2011 by ProjectsGeek Leave a Comment

Macro Processor Pass Two in C Language

Implementation of Macro Processor Pass Two. Following cases to be considered

a)Macro without any parameters

b)Macro with Positional Parameters

c)Macro with Key word parameters

d)Macro with positional and keyword parameters

Macro definition and Call Macro Expansion,Design of Macro Processor Definition and expansion processing.Algorithms along with Data structures Nested Macro calls,Call within a call and definition within a definition.

Macro Processor Pass Two Code

 #include  
 #include  
 #include  
 #include  
 FILE *fp;  
 FILE *fp1;  
 FILE *fp2;  
 typedef struct pntab  
 {  
   char par[10];  
 }ptab;  
 typedef struct MNT  
 {  
   char name[10];  
   int nop;  
   int nok;  
   int mdtp;  
   int kpdtp;  
   int noe;  
 }MT;  
 MT mnt[1];  
 ptab pntab[100];  
 /*  
 typedef struct ssntab  
 {  
   char name[50];  
 }ssnt;  
 typedef struct sstab  
 {  
   int val;  
 }sst;  
 sst sstab[50];  
 ssnt ssntab[50];  
 */  
 typedef struct evntab  
 {  
   char name[50];  
 }evnt;  
 evnt evntab[50];  
 typedef struct evtab  
 {  
   int val;  
 }evt;  
 evt evtab[50];  
 typedef struct mdt  
 {  
   char entry[100];  
 }MDT;  
 MDT mdt[100];  
 typedef struct aptab  
 {  
   char value[10];  
 }at;  
 at aptab[100];  
 typedef struct kpdtab  
 {  
   char name[10];  
   char value[10];  
 }ktab;  
 ktab kpdtab[10];  
 void disp_aptab(int len)  
 {  
   printf("\nAPTAB:\n");  
   int i;  
   for(i=0;i<=len;++i)  
   {  
     printf("%d.%s\n",i+1,aptab[i].value);  
   }  
 }  
 void disp_mdt(int len)  
 {  
   printf("MDT:\n");  
   int i=1;  
   while(i<=len)  
   {  
     printf("%d.%s\n",i,mdt[i-1].entry);  
     i++;  
   }  
 }  
 void disp_pntab(int len)  
 {  
   int i;  
   for(i=0;i<=len;++i)  
   {  
     printf("%d.%s\n",i+1,pntab[i].par);  
   }  
 }  
 int search_pntab(char str[],int len)  
 {  
   int i;  
   for(i=0;i<=len;++i)  
   {  
     if(strcmp(str,pntab[i].par)==0)  
     {  
       return i;  
     }  
   }  
   return -1;  
 }  
 void disp_mnt()  
 {  
   printf("\tName\tPP\tKP\tMDTP\tKPDTP\n");  
   printf("\t%s\t%d\t%d\t%d\t%d\n",mnt[0].name,mnt[0].nop,mnt[0].nok,mnt[0].mdtp,mnt[0].kpdtp);  
 }  
 void main()  
 {  
   clrscr();  
   char str[100];  
   int i=0,ptr=-1,j;  
   int nop=0,nok=0,noe=0;  
   fp=fopen("mac.txt","r");  
   if(fp==NULL)  
   {  
     printf("File not found\n");  
     getch();  
     return;  
   }  
   fgets(str,100,fp);  
   if(strcmp("MACRO\n",str)==0)  
     printf("MAcro detected\nExecuting Pass1\n");  
   fgets(str,100,fp);  
   //Creating PNTAB and MNT  
   j=0;  
   while(str[i]!='\t')  
   {  
     mnt[0].name[j]=str[i];  
     i++;j++;  
   }  
   int kpdtab_ptr=0;  
   while(str[i]!='\n')  
   {  
     pntab[ptr].par[j]=NULL;  
     j=0;  
     ptr++;i++;  
     if(str[i]=='&')  
     {  
       i++;  
       ++nop;  
       while(str[i]!=','&&str[i]!='\n')  
       {  
         if(str[i]=='=')  
         {  
           nop--;  
           nok++;  
           i++;  
           strcpy(kpdtab[kpdtab_ptr].name,pntab[ptr].par);  
           if(str[i]!=',')  
           {  
             int k=0;  
             while(str[i]!=','&&str[i]!='\n')  
             {  
               kpdtab[kpdtab_ptr].value[k]=str[i];  
               i++;  
               k++;  
             }  
           }  
         }  
         else  
         {  
           pntab[ptr].par[j]=str[i];  
           j++;i++;  
         }  
       }  
     }  
   }  
   printf("\nPNTAB is\n");  
   disp_pntab(ptr);  
   mnt[0].nop=nop;  
   mnt[0].nok=nok;  
   mnt[0].mdtp=0;  
   mnt[0].kpdtp=0;  
   char label[10],mneu[10],op1[10],op2[10];  
   char intercode[100],buff[10];  
   int x;  
   int mdtp=0;  
   while(!feof(fp))  
   {  
     fgets(str,100,fp);  
     i=0;  
     if(str[0]=='\t')  
     {  
       strcpy(label,NULL);  
       i++;  
     }  
     else  
     {  
       j=0;  
       while(str[i]!='\t'&&str[i]!='\n')  
       {  
         label[j]=str[i];  
         i++;j++;  
       }  
       label[j]=NULL;  
       if(strcmp(label,"MEND")==0)  
       {  
         strcpy(intercode,"\tMEND\n");  
         strcat(intercode,NULL);  
         strcpy(mdt[mdtp].entry,intercode);  
         mdtp++;  
         break;  
       }  
       i++;  
     }  
     j=0;  
     while(str[i]!='\t')  
     {  
       mneu[j]=str[i];  
       i++;j++;  
     }  
     mneu[j]=NULL;  
     j=0;i+=2;  
     while(str[i]!=',')  
     {  
       op1[j]=str[i];  
       i++;j++;  
     }  
     op1[j]=NULL;  
     j=0;i+=2;  
     while(str[i]!='\n')  
     {  
       op2[j]=str[i];  
       i++;j++;  
     }  
     op2[j]=NULL;  
     if(strcmp(mneu,"LCL")==0)  
     {  
       noe++;  
     }  
     strcpy(intercode,NULL);  
     if(strcmp(label,NULL)==0)  
     {  
       strcat(intercode,"\t");  
     }  
     strcat(intercode,mneu);  
     strcat(intercode,"\t");  
     x=search_pntab(op1,ptr);  
     if(x!=-1)  
     {  
       strcat(intercode,"(P,");  
       itoa(x,buff,10);  
       strcat(intercode,buff);  
       strcat(intercode,"),");  
     }  
     if(op2[0]=='=')  
     {  
       strcat(intercode,op2);  
     }  
     else  
     {  
       x=search_pntab(op2,ptr);  
       if(x!=-1)  
       {  
         strcat(intercode,"(P,");  
         itoa(x,buff,10);  
         strcat(intercode,buff);  
         strcat(intercode,")\n\0");  
       }  
     }  
     end:  
     strcat(intercode,NULL);  
     strcpy(mdt[mdtp].entry,intercode);  
     mdtp++;  
 //    getch();  
   }  
   printf("\nMNT:\n");  
   disp_mnt();  
   disp_mdt(mdtp);  
   fp2=fopen("mca.txt","r");//other file is mcal  
   fgets(str,100,fp2);  
   i=0;  
   while(str[i]!=' ')  
     i++;  
   strcpy(buff,NULL);  
   int k=0;  
   int aptab_ptr=0;  
   while(str[i]!='\n')  
   {  
     j=0; i++;  
     while(str[i]!=',' && str[i]!='\n')  
     {  
       if(str[i]=='=')  
       {  
         buff[j]=NULL;  
         x=search_pntab(buff,ptr);  
         strcpy(buff,NULL);  
         j=0;  
         i++;  
         while(str[i]!=',' && str[i]!='\n')  
         {  
           buff[j]=str[i];  
           i++;j++;  
         }  
         buff[j]=NULL;  
         strcpy(aptab[x].value,buff);  
         goto yo;  
       }  
       buff[j]=str[i];  
       i++;j++;  
     }  
     buff[j]=NULL;  
     strcpy(aptab[aptab_ptr++].value,buff);  
     yo:  
   }  
   aptab_ptr+=nok;  
   i=0;  int y;  
   while(i<aptab_ptr) <br="">   {  
     if(strcmp(aptab[i].value,NULL)==0)  
     {  
       y=i-nop;  
       strcpy(aptab[i].value,kpdtab[y].value);  
     }  
     i++;  
   }  
   i=0;           j=0;  
   disp_aptab(ptr);  
   getch();  
   printf("Expanded MAcro is:\n");  
   strcpy(intercode,NULL);  
   while(i<mdtp-1) <br="">   {  
     strcpy(intercode,NULL);  
     j=0;  
     while(mdt[i].entry[j]!='\n')  
     {  
       if(mdt[i].entry[j]=='(')  
       {  
         if(mdt[i].entry[j+1]=='P')  
         {  
           x=(int)mdt[i].entry[j+3]-48;  
           //itoa(aptab[x].value,buff,10);  
           strcat(intercode,aptab[x].value);  
           j=j+4;  
         }  
       }  
       else  
       {  
         x=strlen(intercode);  
         intercode[x]=mdt[i].entry[j];  
         intercode[x+1]=NULL;  
       }  
       j++;  
     }  
     intercode[j]=NULL;  
     printf("%s \n",intercode);  
     i++;  
     //mdt[i].entry  
   }  
   /*while(!feof(fp))  
   {  
     fgets(str,100,fp);  
     printf(str);  
   } */  
   getch();  
 }

Input File

MACRO
INCR    &MEM_VAL,&INCR_VAL,&REG
MOVER    &REG,&MEM_VAL
ADD    &REG,&INCR_VAL
MOVEM    &REG,&MEM_VAL
MEND

Other Projects to Try:

  1. Lexical analyzer Code in C Language
  2. Regular Expression to DFA Code in C Language
  3. Expression Tree using C Language
  4. Stack Operations using C Language
  5. Macro Processor Algorithm

Filed Under: System Programming

Regular Expression to DFA Code in C Language

May 4, 2011 by ProjectsGeek Leave a Comment

Regular Expression to DFA Code in C Language 

Regular Expression to DFA ( To be taken from compiler point of view) .The implementation to be done as per the algorithm covered in the book Compiler Design and Principles.

Regular Expression to DFA Code

 #include  
 #include  
 #include  
 #include  
 typedef struct tree  
 {  
   char ch;  
   int pos;  
   int nullable;  
   int fpos[5];  
   int lpos[5];  
   struct tree * lc;  
   struct tree * rc;  
 }node;  
 int dfaa[30],df=0;  
 typedef struct foll  
 {  
   int follpos[10];  
   char ch;  
 }follpos;  
 follpos folltab[100];  
 char inpt[10];  
 void follow(node *);  
 node* alloc(char ch)  
 {  
   node * temp;  
   temp=(node *)malloc(sizeof(node));  
   temp->nullable=1;  
   temp->lc=NULL;  
   temp->rc=NULL;  
   temp->ch=ch;  
   temp->fpos[0]=-1;  
   temp->lpos[0]=-1;  
   return temp;  
 }  
 void unio(int [],int []);  
 void sort(int []);  
 int check(int[] ,int);  
 void print_follow(int n)  
 {  
   printf("FOLLOWPOS\n");  
   printf("POS\tNAME\tFOLLOWPOS\n");  
   for(int i=1;i<=n;++i)  
   {  
     printf("%d\t%c\t",i,folltab[i].ch);  
     int j=0;  
     while(folltab[i].follpos[j]!=-1)  
     {  
       printf("%d ",folltab[i].follpos[j]);  
       j++;  
     }  
     printf("\n");  
   }  
 }  
 void print_nullable(node *root)  
 {  
   if(root!=NULL)  
   {  
     print_nullable(root->lc);  
     print_nullable(root->rc);  
     printf("%c\t",root->ch);  
     int i=0;  
     while(root->fpos[i]!=-1)  
     {  
       printf("%d ",root->fpos[i]);  
       i++;  
     }  
     printf("\t");  
     i=0;  
     while(root->lpos[i]!=-1)  
     {  
       printf("%d ",root->lpos[i]);  
       i++;  
     }  
     printf("\n");  
   }  
 }  
 node * create(char str[],int *l)  
 {  
   node * nw;  
   nw=alloc(str[*l]);  
   if(str[*l]=='*'||str[*l]=='|'||str[*l]=='.')  
   {  
     if(str[*l]!='*')  
     {  
       (*l)--;  
       nw->nullable=0;  
       nw->rc=create(str,l);  
     }  
     (*l)--;  
     nw->lc=create(str,l);  
   }  
   else  
     nw->nullable=0;  
   return nw;  
 }  
 void inorder(node *root)  
 {  
   if(root!=NULL)  
   {  
     inorder(root->lc);  
     printf("%c",root->ch);  
     inorder(root->rc);  
   }  
 }  
 void create_nullable(node * root,int *pos)  
 {  
   if(root->lc!=NULL)  
     create_nullable(root->lc,pos);  
   if(root->rc!=NULL)  
     create_nullable(root->rc,pos);  
   if(root->lc==NULL && root->rc==NULL)  
   {  
     root->pos=(*pos);  
     root->fpos[0]=root->lpos[0]=(*pos);  
     root->fpos[1]=root->lpos[1]=-1;  
     folltab[*pos].ch=root->ch;  
     folltab[*pos].follpos[0]=-1;  
     (*pos)++;  
   }  
   else  
   {  
     if(root->ch=='|')  
     {  
       unio(root->fpos,root->lc->fpos);  
       unio(root->fpos,root->rc->fpos);  
       unio(root->lpos,root->lc->lpos);  
       unio(root->lpos,root->rc->lpos);  
     }  
     else if(root->ch=='*')  
     {  
       unio(root->fpos,root->lc->fpos);  
       unio(root->lpos,root->lc->lpos);  
     }  
     else if(root->ch=='.')  
     {  
       if(root->lc->nullable==1)  
       {  
         unio(root->fpos,root->rc->fpos);  
       }  
         unio(root->fpos,root->lc->fpos);  
         sort(root->fpos);  
       if(root->rc->nullable==1)  
       {  
         unio(root->lpos,root->lc->lpos);  
       }  
         unio(root->lpos,root->rc->lpos);  
         sort(root->lpos);  
     }  
     follow(root);  
   }  
 }  
 void follow(node *root)  
 {  
   int i=0;  
   if(root->ch=='*')  
   {  
     while(root->lpos[i]!=-1)  
     {  
       unio(folltab[root->lpos[i]].follpos,root->fpos);  
       i++;  
     }  
   }  
   else if(root->ch=='.')  
   {  
      while(root->lc->lpos[i]!=-1)  
      {  
       unio(folltab[root->lc->lpos[i]].follpos,root->rc->fpos);  
       i++;  
      }  
   }  
 }  
 void unio(int arr1[],int arr2[])  
 {  
   int i=0;  
   while(arr1[i]!=-1)  
     i++;  
   int j=0;int k=0;  
   while(arr2[j]!=-1)  
   {  
     for(k=0;k<i;++k) <br="">     {  
       if(arr2[j]==arr1[k])  
         break;  
     }  
     if(k==i)  
     {  
       arr1[i]=arr2[j];  
       i++;  
     }  
     j++;  
   }  
   arr1[i]=-1;  
 }  
 void sort(int a[])//insertion sort  
 {  
   int i,j,temp;  
   for(i=1;a[i]!=-1;i++)  
   {  
     temp=a[i];  
     for(j=i-1;j>=0&&temp<a[j];j--) <br="">       a[j+1]=a[j];  
     a[j+1]=temp;  
   }  
 }  
 int state[10][10];  
 void dfa()  
 {  
   int j=0,k=0,temp[10];  
   temp[0]=-1;  
   int nos=1;  
   for(int i=0;i<10;++i)  
     state[i][0]=-1;  
   i=0;    int m;  
   unio(state[0],folltab[1].follpos);  
   while(1)  
   {  
     for(i=0;inpt[i]!=NULL;++i)  
     {  
       for(j=0;state[k][j]!=-1;++j)  
       {  
         if(folltab[state[k][j]].ch==inpt[i])  
           { unio(temp,folltab[state[k][j]].follpos);  }  
         }  
           m=check(temp,nos);  
            if(m==-1)  
            {  
             unio(state[nos++],temp);  
             m=nos-1;  
            }  
           dfaa[df++]=m;  
       temp[0]=-1;  
     }  
     if(k==nos-1)  
       break;  
     k++;  
   }  
 }  
 int check(int temp[],int nos)  
 {  
   for(int i=0;i<nos;++i) <br="">   {  
     for(int j=0;temp[j]!=-1;++j)  
     {  
       if(temp[j]!=state[i][j])  
         break;  
     }  
     if(temp[j]==-1 && state[i][j]==-1)  
       return i;  
   }  
   return -1;  
 }  
 void display_dfa()//displaying DFA table  
 {  
   int i,j,k;  
   printf("\nDFA TABLE\n ");  
   for(i=0;inpt[i]!=NULL;i++)  
     printf("\t%c",inpt[i]);  
   for(j=0;j<(df/i);j++)  
   {  
     printf("\n%c\t",j+65);  
     for(k=j*i;k<(j*i)+i;k++)  
       printf("%c\t",dfaa[k]+65);  
   }  
   getch();  
 }  
 void main()  
 {  
   clrscr();  
   char str[50];  
   inpt[0]=NULL;  
   printf("Enter the postfix expression\n");  
   scanf("%s",str);  
   node * root;   
   int l;  
   strcat(str,"#.\0");  
   l=strlen(str);  
   l--;  
   int j=0;  
   for(int i=0;i<l-1;++i) <br="">   {  
     j=0;  
     while(inpt[j]!=NULL)  
     {  
       if(inpt[j]==str[i])  
         break;  
       j++;  
     }  
     if(inpt[j]!=str[i] && str[i]!='|' && str[i]!='*' && str[i]!='.')  
     {  
       inpt[j]=str[i];  
       inpt[j+1]=NULL;  
     }  
   }  
   int pos=1;  
   root=create(str,&l);  
   create_nullable(root,&pos);  
   printf("NULLABLE TABLE\nElement\tFPOS\tLPOS\n");  
   print_nullable(root->lc);  
   print_follow(pos-2);  
   dfa();  
   display_dfa();  
 }

 

Other Projects to Try:

  1. Prims algorithm Code in C Language
  2. BFS AND DFS Algorithm using C Language
  3. Regular Expression to DFA
  4. Expression Tree using C Language
  5. Lexical analyzer Code in C Language

Filed Under: System Programming

Lexical analyzer Code in C Language

May 4, 2011 by ProjectsGeek Leave a Comment

Lexical analyzer Code in C Language

Implement Lexical Analyzer code for subset of C using C Language.

Lexical Analysis-Finite Automate, Regular Expression, RE to DFA,Implementation of lexical Analyzer,Syntax Analysis,Context Free Grammars ,Derivation of Parse Tress,Parsers,Top Down Parsers: Recursive Descent Parser, Predictive Parser,Bottom Up Parsing Shift Reduce Parser, SLR parser and Lexical analyzer Code.

 Lexical analyzer Code

#include  
 #include  
 #include  
 #include  
 #define max 100  
 typedef struct lit_tab  
 {  
   char token[max];  
 }littab;  
 typedef struct iden_tab  
 {  
   char token[max];  
 }identab;  
 typedef struct ust  
 {  
   char token[max];  
   char type;  
   int pos;  
 }ustx;  
 littab lit_tab[50];  
 identab iden_tab[50];  
 ustx ust[100];  
 int ust_ptr=0;  
 char terminal[max][max]={"{","}","(",")","<",">","<=",">=","=",",",";","\"","+","-","*","/","void","printf","int","float","if","else"};  
 void print_ust()  
 {  
   printf("UST\n");  
   int i=0;  
   printf("TOKEN\tTYPE\tPOS\n");  
   while(i<ust_ptr) <br="">   {  
     printf("%s\t%c\t%d\n",ust[i].token,ust[i].type,ust[i].pos);  
     i++;  
     getch();  
   }  
 }  
 void print_ter()  
 {  
   printf("Literal Table");  
   int i=0;  
   clrscr();  
   while(strcmp(terminal[i],NULL)!=0)  
   {  
     printf("%d.%s\n",i+1,terminal[i]);  
     i++;  
   }  
   getch();  
 }  
 void print_lit()  
 {  
   printf("\nLiteral Table");  
   int i=0;  
   clrscr();  
   while(strcmp(lit_tab[i].token,NULL)!=0)  
   {  
     printf("%d.%s\n",i+1,lit_tab[i].token);  
     i++;  
   }  
   getch();  
 }  
 void print_iden()  
 {  
   printf("\nIdentifier Table");  
   int i=0;  
   clrscr();  
   while(strcmp(iden_tab[i].token,NULL)!=0)  
   {  
     printf("%d.%s\n",i+1,iden_tab[i].token);  
     i++;  
   }  
   getch();  
 }  
 int search_lit(char str[])  
 {  
   int i=0;  
    while(strcmp(lit_tab[i].token,NULL)!=0)  
    {  
     if(strcmp(lit_tab[i].token,str)==0)  
       return i;  
     i++;  
    }  
    return -1;  
 }  
 int insert_lit(char str[])  
 {  
   int i=0;  
   while(strcmp(lit_tab[i].token,NULL)!=0)  
   {  
     i++;  
   }  
   strcpy(lit_tab[i].token,str);  
   return i;  
 }  
 int search_iden(char str[])  
 {  
   int i=0;  
    while(strcmp(iden_tab[i].token,NULL)!=0)  
    {  
     if(strcmp(iden_tab[i].token,str)==0)  
       return i;  
     i++;  
    }  
    return -1;  
 }  
 int insert_iden(char str[])  
 {  
   int i=0;  
   while(strcmp(iden_tab[i].token,NULL)!=0)  
   {  
     i++;  
   }  
   strcpy(iden_tab[i].token,str);  
   return i;  
 }  
 int search(char str[])  
 {  
   int i=0;  
   while(strcmp(terminal[i],NULL)!=0)  
   {  
     if(strcmp(terminal[i],str)==0 )  
       return i;  
     i++;  
   }  
   return -1;  
 }  
 void ust_insert(char token[],char type,int pos)  
 {  
   strcpy(ust[ust_ptr].token,token);  
   ust[ust_ptr].type=type;  
   ust[ust_ptr].pos=pos;  
   ust_ptr++;  
 }  
 void main()  
 {  
   FILE *fp;  
   clrscr();  
   fp=fopen("lex.txt","r");  
   if(fp==NULL)  
   {  
     printf("File Not Found");  
     return;  
   }  
   char str[max],token[max];  
   int i,j;  
   while( !feof(fp) )  
   {  
     fgets(str,max,fp);  
     i=0;  
     strcpy(token,NULL);  
     while(str[i]!='\n' && str[i]!=NULL)  
     {  
       while(str[i]==' ' || str[i]=='\t')  
         i++;  
       j=0;  
       if(str[i]=='/')  
       {  
         if(str[i+1]=='/')  
         {  
           fgets(str,max,fp);  
           continue;  
         }  
         else if(str[i+1]=='*')  
         {  
           i+=2;  
           while(str[i]!='*' && str[i+1]!='/')  
           {  
             if(str[i]=='\n')  
             {  
               fgets(str,max,fp);  
               i=0;  
             }  
             i++;  
           }  
           i+=2;  
         }  
       }  
       while(str[i]!=' ' && str[i]!='\t' && str[i]!='\n')  
       {  
         if(str[i-1]=='"' && str[i]!=')')  
         {  
           while(str[i]!='"')  
           {  
             token[j]=str[i];  
             j++;i++;  
           }  
           break;  
         }  
         token[j]=str[i];  
         j++;  
         i++;  
         if(ispunct(str[i]))  
             //if(str[i]=='(' || str[i]==')' ||str[i]==';' ||str[i]==','||str[i]=='+'||str[i]=='='||str[i]=='-'||str[i]=='/'||str[i]=='*')  
           break;  
         if(ispunct(str[i-1]) )  
             //if(str[i-1]==','||str[i-1]=='='||str[i-1]=='/'||str[i-1]=='+'||str[i-1]=='-'||str[i-1]=='*')  
           break;  
       }  
       token[j]=NULL;  
       int x;  
       int l=strlen(token);  
       int pos;  
       x=search(token);  
       if(x!=-1)  
         ust_insert(token,'T',x);  
       else if(str[i-l-1]!='"' && !(token[0]>='0'&& token[0]<='9')&&strcmp(token,NULL)!=0 )  
       {  
         x=search_iden(token);  
         if(x==-1)  
         {  
           pos=insert_iden(token);  
           ust_insert(token,'I',pos);  
         }  
         else  
           ust_insert(token,'I',x);  
       }  
       else if( strcmp(token,NULL)!=0)  
       {  
         x=search_lit(token);  
         if(x==-1)  
         {  
           pos=insert_lit(token);  
           ust_insert(token,'L',pos);  
         }  
         else  
           ust_insert(token,'L',x);  
       }  
     }  
   }  
   print_ter();  
   print_lit();  
   print_iden();  
   print_ust();  
   getch();  
 }

 

Other Projects to Try:

  1. Prims algorithm Code in C Language
  2. Breadth First and Depth First Search C Language
  3. Dijkstra Algorithm in C Language
  4. BFS AND DFS Algorithm using C Language
  5. Lexical Analyzer for Subset of C

Filed Under: System Programming

Text or Screen Editor in C++ Language

May 4, 2011 by ProjectsGeek Leave a Comment

Text or Screen Editor in C++ Language

Write a program in C++ Language to implement a Text or Screen Editor which can edit the entered text on screen.Program should make a file which will be used for storing text .

Text or Screen Editor in C++ Language Code

 #include  
 #include  
 #include  
 #define left 21  
 #define top 7  
 #define right 59  
 #define bottom 24  
 void main()  
 {  
   clrscr();  
   window(left,top-1,right,bottom);  
   char buff[100][40];  
   FILE *fp;  
   fp=fopen("editfile.txt","w");  
   clrscr();  
   cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r");  
   int x=wherex();  
   int y=wherey();  
   //gotoxy(x,y);  
   char ch;  
   int row;  
   int col;   
   int i;  
   do  
   {  
     flushall();  
     ch=getch();  
     int i=0,j=0;  
     if(ch==0)  
     {  
       ch=getch();  
     }  
     //int  
     char c;  
     switch(ch)  
     {  
       case '='://open  
         fp=fopen("editfile.txt","r");  
         i=0;  
         clrscr();  
         while(i<15)  
         {  
           c=fgetc(fp);  
           if(c=='\n')  
           {  
             i++;  
           }  
           cprintf("%c",c);  
         }  
         getch();  
       case '<':  
          //save  
         i=1;  
         fp=fopen("editfile.txt","w");  
         while(i<16)  
         {  
           j=1;  
           while( buff[i][j]!='~' && buff[i][j]!='\r')  
           {  
             fputc(buff[i][j],fp);  
             j++;  
           }  
           fputc('\n',fp);  
           i++;  
         }  
         fputc('\0',fp);  
         getch();  
         clrscr();  
         gotoxy(x,y);  
         cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r");  
         break;  
       case ';': //NEW FILE  
         //cprintf("yo");  
         clrscr();  
         cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r");  
         cprintf("NEW FILE CREATED\n\r");  
         row=1;  
         col=0;  
         i=0;  
         while(i<15)  
         {  
           strcpy(buff[i],NULL);  
           buff[i][0]='~';  
           buff[i][1]='~';  
           buff[i][2]=NULL;  
           i++;  
         }  
         break;  
       case '>'://exit t  
         break;  
       case '\r':// return character next line  
         row++;  
         col=0;  
         gotoxy(x+col,y+row);  
         break;  
       case 'P':  
         row++;  
         gotoxy(x+col,y+row);  
         break;  
       case 'H':  
         if(row!=1)  
         {  
           row--;  
           gotoxy(x+col,y+row);  
         }  
         break;  
        case 'M':  
         col++;  
         if(col==39)  
         {  
           col=0;  
           row++;  
         }  
         gotoxy(x+col,y+row);  
         break;  
        case 'K':  
         col--;  
         if(col==-1)  
         {  
           col=0;  
         }  
         gotoxy(x+col,y+row);  
         break;  
        case '\b':  
          if((col-1)==-1)  
          {  
           break;  
          }  
          if(buff[row][col+1]=='~')  
          {  
           buff[row][col]='~';  
           buff[row][col+1]=NULL;  
           gotoxy(x+col-1,y+row);  
           cprintf(" ");  
           gotoxy(x+col-1,y+row);  
           col--;  
          }  
         else  
          {  
           i=strlen(buff[row]);  
           j=col;  
           gotoxy(x+col-1,y+row);  
           while(j<=i)  
           {  
             buff[row][j]=buff[row][j+1];  
             if(buff[row][j+1]=='~')  
               break;  
             cprintf("%c",buff[row][j+1]);  
             j++;  
           }  
           cprintf(" ");  
           buff[row][i-1]=NULL;  
           gotoxy(x+col-1,y+row);  
           col--;  
          }  
         break;  
        case 'S':  
        if(buff[row][col+1]=='~')  
        {  
         buff[row][col]='~';  
         buff[row][col+1]=NULL;  
         gotoxy(x+col-1,y+row);  
         cprintf(" ");  
         gotoxy(x+col,y+row);  
        }  
        else  
        {  
         i=strlen(buff[row]);  
         j=col+1;  
         gotoxy(x+col,y+row);  
         while(j<=i)  
         {  
           buff[row][j]=buff[row][j+1];  
           if(buff[row][j+1]=='~')  
             break;  
           cprintf("%c",buff[row][j+1]);  
           j++;  
         }  
         cprintf(" ");  
         buff[row][i-1]=NULL;  
         gotoxy(x+col,y+row);  
        }  
         break;  
       default:  
         //row=where  
         col++;  
         if(col==39)  
         {  
           row++;  
           col=0;  
           gotoxy(x+col,y+row);  
         }  
         i=strlen(buff[row]);  
         if( (strlen(buff[row])-1)         {  
           for(i=strlen(buff[row])-1;i<col;++i) <br="">           {  
             buff[row][i]=' ';  
           }  
         }  
           //  else  
          //  col++;  
         buff[row][col+1]='~';  
         buff[row][col]=ch;  
         buff[row][col+2]=NULL;  
         cprintf("%c",ch);  
     }  
   }while(ch!='>');  
 }

 

Other Projects to Try:

  1. How to Implement Hash Table using C language
  2. Hash table code in C Language
  3. Single Link List code using C Language
  4. Applet Text Editor
  5. Text Editor in Java Project

Filed Under: System Programming

  • « Go to Previous Page
  • Page 1
  • Page 2

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy