Loading

Archive for 06/01/2012 - 07/01/2012

Lex and Yacc Calculator

Lex and Yacc Program to Implement Simple Calculator

Lex File -


 %{
       #include<math.h>
       #include"y.tab.h"    //for left,right,up & down
%}
%%

[0-9]+|[0-9]*\.[0-9]+ {
                       yylval.p = atof(yytext);
                       return num;        //return nonterminal
                       }

sin {return SIN;}    //return token SIN to YACC
cos {return COS;}    //return token COS to YACC
tan return TAN;        //return token TAN to YACC
log return LOG;        //return token LOG to YACC
sqrt return SQRT;    //return token SQRT to YACC
[\t];
\n      return 0;
.       return yytext[0];


%%

Yacc File

 %{
       #include<stdio.h>
       #include<math.h>
%}

%union                //to define possible symbol types
{ double p;}
%token<p>num
%token SIN COS TAN LOG SQRT

/*Defining the Precedence and Associativity*/

%left '+','-'            //lowest precedence
%left '*','/'            //highest precedenc
%nonassoc uminu            //no associativity
%type<p>exp            //Sets the type for non - terminal

%%

/* for storing the answer */
ss: exp {printf("=%g\n",$1);}

/* for binary arithmatic operators */
exp :    exp'+'exp      { $$=$1+$3; }
       |exp'-'exp      { $$=$1-$3; }
       |exp'*'exp      { $$=$1*$3; }
       |exp'/'exp      {
                               if($3==0)
                               {
                                       printf("Divide By Zero");
                                       exit(0);
                               }
                               else $$=$1/$3;
                       }
       |'-'exp         {$$=-$2;}
       |'('exp')'      {$$=$2;}
       |SIN'('exp')'   {$$=sin($3);}
       |COS'('exp')'   {$$=cos($3);}
       |TAN'('exp')'   {$$=tan($3);}
       |LOG'('exp')'   {$$=log($3);}
       |SQRT'('exp')'  {$$=sqrt($3);}
       |num;
%%

/* extern FILE *yyin; */
main()
{
       do
       {
               yyparse();    /* repeatedly tries to parse the                 sentence until the i/p runs out */
       }while(1);

}

yyerror(s)            /* used to print the error message when an                 error is parsing of i/p */

char *s;
{
       printf("ERROR");
}

Click Here to Download Source Code with Executable Program

Leave a comment

Screen Editor

C - Program to Implement Screen Editor


#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#define RIGHT 77
#define LEFT  75
#define UP    72
#define DOWN  80
#define DELETE 83
#define BACKSPACE 8
#define F1     59
#define F2     60
#define F3     61

int cx=1,cy=1,cxx=0,fchar=0,tchar=79;
int nline=0;
int fline=0,tline=0;
int cline=0;
/***************************************************
cx   :  X-Cordinate of the cursor
cy   :  Y-Cordinate of the cursor
cxx  :  position of the cursor in the current line in the file
fchar,tchar
     : Only a portion of the line is displayed on the screen. fchar gives
       the left position and tchar gives the right position in the line.
nline: Number of lines in the file
fline,tline
     : In this program,21 lines of the file are displayed at a time. These
       lines are from fline to tline.
cline: It gives the line number of the line on which the cursor is placed
*/

static char buffer[80][121];//The file may contain maximum of 80 lines,
                //each line may contain maximum of 118 characters
int lengthof(int cline) ;//Gives the length of a line
void  displine(int cline);

void dispmenu()
  {
    int i;
    gotoxy(1,22);
    printf("---------------------------------------------------------------");
    gotoxy(1,23);
    printf("F1 - Save    F3- Exit");
    gotoxy(1,24);
    printf("---------------------------------------------------------------");
  }

int spaceline(int cline)  //The current line may contain only white spaces
  {
    int j;
    for(j=0;j<120;j++)
        if(buffer[cline][j]!=' ' )
            return(0);
    return(1);
}

void display() //Display contents of the screen buffer
 {
   int i,j;
   clrscr();
   for(i=fline;i<=tline;i++ )
    {
    gotoxy(1,i+1-fline);
    for(j=fchar;j<=tchar;j++)
        {
        putchar(buffer[i][j]);
        }
    }
   dispmenu();
   gotoxy(cx,cy);
 }

char read()  //Read the next character
 {
   char x;
   x=getch();
   if(x==0)//Control character
    x=getch();
  return(x);
 }
void Delete(int cline,int pos)//Delete the current character
 {
   int j;
   if(pos<0)
    return;
   for(j=pos+1;buffer[cline][j]!=0;j++)//Shift characters left by 1 place
    buffer[cline][j-1]=buffer[cline][j];
    buffer[cline][j-1]=' ';
 }


void deleteline() //Delete the current line
  {
    int i=0,j;
    if(nline>1)
      {
        for(i=cline+1;i<=tline;i++)
            strcpy(buffer[i-1],buffer[i]);
        nline--;
        if(cline>nline)
          {
            tline--;
            cy=cy-1;
            cx=1;
            cline=cline-1;
          }
      }
 display();
 }


void insertline(int cline1,char x,int pos)
 {
     int i=0,j,length,l;
     char buff[180];
   if(x==13)//Insert a new line, it breaks the line into two lines
    {
    for(i=nline;i>cline1;i--)//Shift lines by 1 position
        strcpy(buffer[i+1],buffer[i]);
    strcpy(buffer[cline1+1],buffer[cline1]+pos);//Line after Cursor position
    for(i=pos;i<=119;i++)//Fill spaces in the remaining portion
        buffer[cline1][i]=' ';
    buffer[cline1][120]=0;//End of text marker
    for(i=strlen(buffer[cline+1]);i<120;i++) //Fill spaces in the broken line
        buffer[cline1+1][i]=' ';
    buffer[cline1+1][120]=0;
    nline++; //Adjust coordinate variables
    cline++;
    tline++;
    cy=cy+1;
    cxx=0;
    cx=1;
    if(cy>21)//Adjustment for the last line of the screen
      {
        fline++;
        cy--;
      }

   }
 else
  {
    for(i=118;i>=pos ;i--)//Shift right and insert the current character
        buffer[cline1][i+1]=buffer[cline1][i];
    buffer[cline1][i+1]=x;
  }
display();
gotoxy(cx,cy);//Position the cursor
}

void save(char filename[])//Save the file
 {
    FILE *ptr; int i,j ;
    ptr=fopen(filename,"w");
    if(ptr==NULL)
      {
        printf("\nCould not open the file");
        getch();
      }

  for(i=0;i<nline;i++)
   {
    buffer[i][118]='\n';
    buffer[i][119]=0;
    for(j=0;j<=119 && buffer[i][j]!=0;j++)
        putc(buffer[i][j],ptr);
   }
  fclose(ptr);
}

void main()
   {
    static char filename[50];
    FILE *ptr;
    int length,i;
    char x;
    buffer[0][0]=0;//Empty buffer
    clrscr();
    printf("\nEnter the file name : ");
    gets(filename);
    ptr=fopen(filename,"r");
    if(ptr==NULL)
      {
        ptr=fopen(filename,"w");
        putc(' ',ptr);
        fclose(ptr);
        ptr=fopen(filename,"r");
      }

    if(ptr!=NULL)
       {
        while(!feof(ptr)) //Read the file in the screen buffer
          {
            tline++;
            i=0;
            fgets(buffer[nline],120,ptr);
            while(buffer[nline][i]!='\n' && buffer[nline][i]!=0)
                i++;
            for(;i<119;i++)
                buffer[nline][i]=' ';
            buffer[nline][i]=0;
            nline++;
           }
       }
    fclose(ptr);

    if(tline>20)
        tline=20; //Maximum of 21 lines to be displayed
    display();
    gotoxy(cx,cy);
    x=read(); //Read the next key
    fchar=0;
    tchar=lengthof(0) - 1;
    if(tchar<0)
        tchar=0;
    if(tchar>79)
        tchar=79;
    while(x!=F3)
       {
        switch(x)
          {
            case F1:fclose(ptr);
                save(filename);
                break;
            case UP:
                if(cline>0)
                    if(cy>1 )//Scroll down
                       {
                        cy--;
                        cline--;
                        gotoxy(cx,cy);
                       }
                    else
                       {
                        fline--;
                        tline--;
                        cline--;
                        display();
                        gotoxy(cx,cy);

                        }
                break;
            case DOWN:
                  if(cline<nline)
                    if(cy<21 )//Scroll Up
                        {
                        cy++;
                        cline++;
                        gotoxy(cx,cy);
                        }
                    else
                        {
                        fline++;
                        tline++;
                        cline++;
                        display();
                        gotoxy(cx,cy);
                        }
                  break;

            case RIGHT:
                   if(cxx<lengthof(cline))
                    if(cx<80 )
                      {
                        cx++;
                        cxx++;
                        gotoxy(cx,cy);
                      }
                    else
                      { //Scroll left
                        cxx++;
                        fchar++;tchar++;
                        display();
                      }
                   break;

            case LEFT:
                  if(cxx>0)
                      if(cx>1)
                    {
                        cx--;
                        cxx--;
                        gotoxy(cx,cy);
                    }
                      else
                    {  //Scroll right
                        cxx--;
                        fchar--;tchar--;
                        display();
                    }
                  break;
            case DELETE:
                   if(cxx>0 || ! spaceline(cline))
                     {
                    tchar--;
                    Delete(cline,cxx);//Delete the current character
                    display();
                    gotoxy(cx,cy);
                     }
                   else
                    deleteline(cline);//Delete the current line

                   break;
            case BACKSPACE:
                   if(cxx>0 )
                     {
                    tchar--;
                    Delete(cline,cxx-1);//Delete the previous character
                    cxx--;
                    if(cx>1)
                       cx--;
                    display();
                    gotoxy(cx,cy);
                     }

                   break;

            case 13://Enter is pressed
                insertline(cline,x,cxx);
                break;
            default:
                if(isalnum(x)||ispunct(x)||isspace(x))
                   {
                    insertline(cline,x,cxx);
                    cx++;cxx++;
                    gotoxy(cx,cy);
                   }
                break;
         }
    x=read();
     }


  }

int lengthof(int cline)
  {
    return(strlen(buffer[cline]));
  }

Click Here to Download Source Code with Executable Program

Leave a comment

Tower of Hanoi

C - Program to Implement Problem of Tower of Hanoi

 

 #include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>

class tower
{
   public:
        int count;
        void toh(int n,char x,char y,char z);
};


int main()
{
  int n;
  char x,y,z;
  char k='y';
  tower t;
  x='A';
  y='B';
  z='C';

  do
  {
    clrscr();
    float toc;
    clock_t end,start;
    start=clock();
    cout<<"\n\t\t\t\t Tower Of Hanoi ";
    cout<<"\n\t\t\t\t----------------";
    cout<<"\n\n\t\tEnter No of Disks :: ";
    cin>>n;
    t.count=0;
    t.toh(n,x,y,z);
    cout<<"\n\n\t\tNo of Steps Performed :: "<<t.count;
    end=clock();
    toc=(end - start)/CLK_TCK;
    cout<<"\n\t\tTime Complexity :: "<<toc;
    cout<<"\n\n\t\t\tDo you want to continue?(y/n)";
    k=getche();
  }while(k=='y');
  return 0;
}

void tower::toh(int n,char x,char y,char z)
{
   if(n>=1)
   {
     toh(n-1,x,z,y);
     printf("\n\t\tMove  Disk %d from %c to %c",n,x,y);
     count++;
     toh(n-1,z,y,x);
   }
}

Click Here to Download Source Code with Executable Program

Online Blackjack
Online casino gambling to play conveniently offer over 100 top online casino games play slots poker online blackjack

Gestion Sav
Newwayservice est un excellent logiciel sav. (service après-vente)

Leave a comment

RE to DFA Conversion

C - Program to Implement Regular Expression to DFA Conversion




#include<stdio.h>
#include<conio.h>

char Po[25], In[25];
int node[10][10], flps[10][10], position[10][10], DF[10][10];
int NN=1, DD=1, S=0, var=0, terp=1, v;

struct STACK
{
   char data;
   struct STACK *D;
   struct STACK *next,*L,*R;
   int FP[10],LP[10];
}  *O, *A;

void PUSH(char a)
{
   struct STACK *t;
   t=(struct STACK *)malloc(sizeof(struct STACK));
   t->data=a;
   if (O!=NULL) t->next=O;
   else         t->next=NULL;
   O=t;
}

char POP()
{
   char l;
   l=O->data;
   if(O->next!=NULL) O=O->next;
   else              O=NULL;
   return l;
}

void PUSHNODE(struct STACK *a)
{
   struct STACK *t;
   t=(struct STACK *)malloc(sizeof(struct STACK));
   t->D=a;
   if(O!=NULL) t->next=O;
   else        t->next=NULL;
   O=t;
}

struct STACK *POPNODE()
{
   struct STACK *t;
   t=(struct STACK *)malloc(sizeof(struct STACK));
   t=O->D;
   if(O->next!=NULL) O=O->next;
   else              O=NULL;
   return t;
}

void INFIX2POSTFIX(char I[25])
{
   int i,j,k;
   char p;
   for(i=0;I[i]!='\0';i++){
       if(I[i]=='(')
      PUSH('(');
       else if(I[i]==')')
      while(1){
           p=POP();
           if(p!='(') Po[v++]=p;
           else         break;
      }
       else if(I[i]=='+'){
      while((O->data=='*'||O->data=='+'||O->data=='.')&&O!=NULL)
           Po[v++]=POP();
      PUSH(I[i]);
       }
       else if(I[i]=='.'){
      while((O->data=='*'||O->data=='.')&&O!=NULL)
           Po[v++]=POP();
      PUSH('.');
       }
       else if(I[i]=='*'&&O!=NULL)
           PUSH(I[i]);
       else    Po[v++]=I[i];
   }
   while(O!=NULL){
    p=POP();
    if(p!='(') Po[v++]=p;
   }
   Po[v++]='$';
   Po[v++]='.';
   Po[v]='\0';
}

void FORMTREE(char Po[])
{
   int i,j,k;
   struct STACK *N;
   O=NULL;
   for(i=0;Po[i]!='\0';i++){
       N=(struct STACK *)malloc(sizeof(struct STACK));
       N->data=Po[i]; N->L=NULL; N->R=NULL; N->next=NULL;
       N->FP[0]=0; N->LP[0]=0;
       if(Po[i]=='.'||Po[i]=='+'){
      N->R=POPNODE();
      N->L=POPNODE();
       }
       else if(Po[i]=='*'){
      N->L=POPNODE();
      N->R=NULL;
       }
       PUSHNODE(N);
   }
}
void FLPDISP (struct STACK *a)
{
   int i;
   if(a!=NULL){
      FLPDISP(a->L);
      FLPDISP(a->R);
      S++;
      printf("\n    %c",a->data);
      printf("\nFIRSTPOS -> ");
      for(i=1;i<=a->FP[0];i++)
      printf(" %d",a->FP[i]);
      printf("\nLASTPOS  -> ");
      for(i=1;i<=a->LP[0];i++)
      printf(" %d",a->LP[i]);
      printf("\n---------------");
      getch();
   }
}


void FP_LP_CAL(struct STACK *a)
{
   if(a!=NULL){
      int i, flg;
      FP_LP_CAL(a->L);
      FP_LP_CAL(a->R);
      if(a->data!='+'&&a->data!='.'&&a->data!='*'){
     a->FP[0]++; a->LP[0]++;
     a->FP[a->FP[0]]=terp;
     a->LP[a->LP[0]]=terp++;
     flg=0;
     for(i=0;i<var;i++)
       if(position[i][0]==a->data){
          position[i][1]++;
          position[i][position[i][1]+1]=terp-1;
          flg=1;
       }
       if(flg==0){
          position[var++][1]=1;
          position[var-1][2]=terp-1;
          position[var-1][0]=a->data;
       }
     }
     else if(a->data=='+'){
       for(i=1;i<=a->L->FP[0];i++){
           a->FP[0]++;
           a->FP[a->FP[0]]=a->L->FP[i];
       }
       for(i=1;i<=a->R->FP[0];i++){
         if(PRESENT(a->FP, a->R->FP[i],1)==0){
        a->FP[0]++;
        a->FP[a->FP[0]]=a->R->FP[i];
         }
       }
       for(i=1;i<=a->L->LP[0];i++){
           a->LP[0]++;
           a->LP[a->LP[0]]=a->L->LP[i];
       }
       for(i=1;i<=a->R->LP[0];i++)
          if(PRESENT(a->LP, a->R->LP[i], 1)==0){
         a->LP[0]++;
         a->LP[a->LP[0]]=a->R->LP[i];
          }
     }
     else if(a->data=='*'){
       for(i=1;i<=a->L->FP[0];i++){
           a->FP[0]++;
           a->FP[a->FP[0]]=a->L->FP[i];
       }
       for(i=1;i<=a->L->LP[0];i++){
           a->LP[0]++;
           a->LP[a->LP[0]]=a->L->LP[i];
       }
     }
     else if(a->data=='.'){
     //firstpos
        for(i=1;i<=a->L->FP[0];i++){
        a->FP[0]++;
        a->FP[a->FP[0]]=a->L->FP[i];
        }
        if(a->L->data=='*')
          for(i=1;i<=a->R->FP[0];i++)
         if(PRESENT(a->FP, a->R->FP[i],1)==0){
            a->FP[0]++;
            a->FP[a->FP[0]]=a->R->FP[i];
         }
     //lastpos
        for(i=1;i<=a->R->LP[0];i++){
        a->LP[0]++;
        a->LP[a->LP[0]]=a->R->LP[i];
        }
        if(a->R->data=='*')
        for(i=1;i<=a->L->LP[0];i++)
        if(PRESENT(a->LP,a->L->LP[i],1)==0){
          a->LP[0]++;
          a->LP[a->LP[0]]=a->L->LP[i];
        }
     }
   }
}
int PRESENT(int p[], int a, int b)
{
   int i,j;
   for(i=b,j=0;j<p[b-1];i++,j++)
       if(p[i]==a)
      return 1;
   return 0;
}

void FLPCAL(struct STACK *a, int n)
{
   int j;
   if(a!=NULL){
      FLPCAL(a->L,n);
      if(a->data=='.'){
     if(PRESENT(a->L->LP,n,1)==1)
        for(j=1;j<=a->R->FP[0];j++)
           if(PRESENT(flps[n],a->R->FP[j],1)==0){
          flps[n][1]++;
          flps[n][flps[n][1]+1]=a->R->FP[j];
           }
      }
      else if(a->data=='*'){
     if(PRESENT(a->LP,n,1)==1)
        for(j=1;j<=a->FP[0];j++)
          if(PRESENT(flps[n],a->FP[j],1)==0){
         flps[n][1]++;
         flps[n][flps[n][1]+1]=a->FP[j];
          }
      }
      FLPCAL(a->R,n);
   }
}
/***************/
void FOLLOWPOS()
{
   int i,j,k;
   A=O;
   flps[0][0]=terp;
   for(i=1;i<=terp;i++){
       flps[i][0]=i;
       flps[i][1]=0;
       FLPCAL(O->D,i);
   }
   O=A;
}

void DFA()
{
   int i,j,k,l,m,fg,find;
   int tmp[10], newn[10];
   node[0][0]=1;
   node[1][0]='A';
   node[1][1]=0;
   for(i=1;i<=O->D->FP[0];i++){
       node[1][1]++;
       node[1][node[1][1]+1]=O->D->FP[i];
   }
   DF[0][0]=var-1;
   for(i=1;i<var;i++)
      DF[0][i]=position[i-1][0];
   for(i=1;i<=node[0][0];i++){
       DF[i][0]=node[i][0];
       for(j=1;j<=DF[0][0];j++){
       tmp[0]=0;
       newn[0]=0;
       for(k=2;k<=node[i][1]+1;k++){
           if(PRESENT(position[j-1],node[i][k],2)==1)
          tmp[++tmp[0]]=node[i][k];
          for(l=1;l<=tmp[0];l++){
             for(m=2;m<=flps[tmp[l]][1]+1;m++)
            if(PRESENT(newn,flps[tmp[l]][m],1)==0){
               newn[0]++;
               newn[newn[0]]=flps[tmp[l]][m];
            }
          }
       }
       printf(" ");
       fg=0;
       for(l=1;l<=node[0][0];l++){
           find=0;
           if(newn[0]==node[l][1])
          for(k=1;k<=newn[0];k++)
             if(PRESENT(node[l],newn[k],2)==0)
              fg=1;
             else find++;
          if(find==newn[0]&&find!=0)
             goto l1;
       }
       if(newn[0]==0){
          DF[i][j]='-';
          goto l2;
       }
       node[0][0]++;
       node[node[0][0]][0]=node[node[0][0]-1][0]+1;
       for(m=0;m<=newn[0];m++)
          node[node[0][0]][m+1]=newn[m];
       DF[i][j]=node[node[0][0]][0];
       goto l2;
l1:       DF[i][j]=node[l][0];
l2:      if(fg==1||fg==0)  printf(" ");
       }
   }
   printf("\n\nNODES:\n\n");
   for(i=1;i<=node[0][0];i++,printf("\n\n"))
      for(j=0;j<=node[i][1]+1;j++)
     if(j==0)
        printf(" %c ",node[i][j]);
     else if(j==1)
        printf(" => ");
     else
        printf(" %d ",node[i][j]);
   printf("\n\nDFA TABLE:\n\n");
   for(i=0;i<=node[0][0];i++,printf("\n\n"))
      for(j=0;j<=DF[0][0];j++)
      if(i==0&&j==0)
         printf("    ");
      else
         printf("%4c",DF[i][j]);
}


void main()
{
   int i,j,k, gd, gm;
   int ch;
   O=NULL; A=NULL; v=0;
do{

   clrscr();

   printf("\n----------------------------");
   printf("\n        RE -> DFA    ");
   printf("\n----------------------------");
   printf("\n     1. ENTER R.E.");
   printf("\n     2. POSTFIX EXPRESSION ");
   printf("\n     3. VIEW FOLLOWPOS");
   printf("\n     4. VIEW DFA ");
   printf("\n     5. QUIT");
   printf("\n---------------------------");
   printf("\n\n    ENTER YOUR CHOICE : ");
  scanf("%d",&ch);
   switch(ch)
   {
      case 1:
           printf("\n\n    ENTER REGULAR EXPRESSION : ");
           scanf("%s",&In);
           break;
      case 2:
           INFIX2POSTFIX(In);
           printf("\n\n    POSTFIX EXPRESSION : \n\n\t%s",Po);
           O=NULL;
           FORMTREE(Po);
           break;
      case 3:
           FP_LP_CAL(O->D);
           FLPDISP(O->D);
           FOLLOWPOS();
           printf("\n\n    FOLLOWPOS :\n\n");
           for(i=1;i<terp;i++)
           {
           for(j=0;j<=flps[i][1]+1;j++)
              if(j!=1)
             printf(" %d ",flps[i][j]);
              printf("\n");
           }
           break;
      case 4:
           printf("\n\n    POSITION MATRIX :\n\n");
           for(i=0;i<var;i++)
           {
           for(j=0;j<=position[i][1]+1;j++)
               if(j==0)
              printf(" %c ",position[i][j]);
               else if (j!=1)
              printf(" %d ",position[i][j]);
               printf("\n\n");
           }
           DFA();
           break;
      case 5:
    printf("\n    Thanks.....\a");

           break;
      default :
           printf("\n\n    SORRY!! WRONG CHOICE!\a");
           break;
     }
   }while(ch!=5);
   getch();
}

Click Here to Download Source Code with Executable Program

Posted in | Leave a comment

Prims Algorithm

C  - Program to Implement Prims Algorithm

 #include<iostream.h>
#include<conio.h>
#include<time.h>
#define infinity 9999

int g[20][20],nodes;
void prims();
void getgraph();

int main()
{
   int i;
   char k='y';
   do
   {
    clrscr();
    float toc;
    clock_t end,start;
    start=clock();
    cout<<"\n\t\t\t\tPrims Algorithm";
    cout<<"\n\t\t\t\t---------------";
    getgraph();
    prims();
    end=clock();
    toc=(end - start)/CLK_TCK;
    cout<<"\n\n\t\tTime Complexity :: "<<toc;
    cout<<"\n\n\t\t\tDo u want to continue?(y/n)";
    k=getche();
   }while(k=='y');
   return 0;
}

void getgraph()
{
    int i,j,k,n,v1,v2,len;
    cout<<"\n\n\t\tEnter the Number of Nodes in Graph :: ";
    cin>>nodes;
    cout<<"\n\t\tEnter the Number of Edges in Graph ::";
    cin>>n;

    for(i=0;i<nodes;i++)
    for(j=0;j<nodes;j++)
        g[i][j]=0;

    for(i=0;i<n;i++)
    {
    cout<<"\n\t\tEnter Edges (V1,V2) ::";
    cin>>v1>>v2;
    cout<<"\n\t\tEnter the Corresponding Weight :: ";
    cin>>len;
    g[v1][v2]=g[v2][v1]=len;
    }
}

void prims()
{
   int tree[20],i,j,k;
   int min,tot,v1,v2;
   tot=0;
   for(i=0;i<nodes;i++)
    tree[i]=0;


   cout<<"\n\t\tMinimal Spanning Tree is :: ";
   tree[0]=1;
   for(k=1;k<=nodes-1;k++)
   {
    min=infinity;
    for(i=0;i<=nodes-1;i++)
    {
        for(j=0;j<=nodes-1;j++)
        {
          if(g[i][j] &&((tree[i] && !tree[j])||(!tree[i] && tree[j])))
          {
            if(g[i][j]<min)
            {
                min=g[i][j];
                v1=i;
                v2=j;
            }
          }
        }
    }
    cout<<"\n\n\t\tEdge ("<<v1<<","<<v2<<")";
    cout<<"\tWeight = "<<min;
    tree[v1]=tree[v2]=1;
    tot=tot + min;
   }
   cout<<"\n\n\t\tTotal Path Length :: "<<tot;
}

Click Here to Download Source Code with Executable Program

Leave a comment

N Queens Problem Recursive

C - Program to Implement N - Queens Problem (Recursive Solution)


 #include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<time.h>

class queen
{
  public:
        int x[20],count;
        void nqueen(int,int);
        int place(int,int);
        void write(int x[],int);
};

int main()
{
  int i,n;
  char k='y';
  queen q;
  do
  {
    clrscr();
    float toc;
    clock_t end,start;
    start=clock();
    cout<<"\n\t\t\t N-Queens Problem";
    cout<<"\n\t\t\t------------------";
    cout<<"\n\n\t\tEnter Size of Chessboard :: ";
    cin>>n;
    q.count=0;
    q.nqueen(1,n);
    cout<<"\n\t\tTotal No of Solutions ::"<<q.count;
    end=clock();
    toc=(end - start)/CLK_TCK;
    cout<<"\n\t\tTime Complexity :: "<<toc;
    cout<<"\n\t\tDo you want to continue?(y/n)";
    k=getche();
  }while(k=='y');
  return 0;
}

void queen::nqueen(int k,int n)
{
  int i;
  for(i=1;i<=n;i++)
  {
    if(place(k,i))
    {
        x[k]=i;
        if(k==n)
            write(x,n);
        else
            nqueen(k+1,n);
    }
  }
}

int queen::place(int k,int i)
{
  int j;
  for(j=1;j<=k-1;j++)
  {
    if((x[j]==i) || (abs(x[j]-i) == abs(j-k)))
        return 0;
  }
  return 1;
}

void queen::write(int x[],int n)
{
  int i,j;
  cout<<"\n\n\t\t"<<count+1<<") Possible Solution :: ";
  for(i=1;i<=n;i++)
  {
    cout<<" "<<x[i];
  }
  cout<<"\n";
  for(i=1;i<=n;i++)
  {
    cout<<"\n\t\t\t";
    for(j=1;j<=n;j++)
    {

    if(j==x[i])
        cout<<"  Q ";
    else
        cout<<"  x ";
    }

  }
  cout<<"\n\n";
  count++;
}

Click Here to Download Source Code with Executable Program.

Leave a comment

N Queens Problem Iterative

C - Program to Implement N - Queens Problem (Iterative Solution)


#include<conio.h>
#include<math.h>
#include<time.h>

#define TRUE 1
#define FALSE 0

void print_solution(int n,int x[])
{

    char c[10][10];
    int i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1; j<=n; j++)
        {
            c[i][j]='-';
        }
    }

    for(i=1;i<=n;i++)
    {
        c[i][x[i]]='Q';
    }

    for( i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            printf("\t%c",c[i][j]);
        }
            printf("\n");
    }

}


int place(int x[],int k)
{       int i;
    for(i=1;i<k;i++)
    {
        if(x[i]==x[k]||i-x[i]==k-x[k]||i+x[i]==k+x[k])
        {
            return FALSE;
        }
    }
    return TRUE;
}

void nqueens(int n)
{
    int x[10];
    int count=0;
    int k=1;

    x[k]=0;

    while(k!=0)
    {

        x[k]=x[k]+1;
        while((x[k]<=n)&&(!place(x,k)))
        {

            x[k]=x[k]+1;
        }
        if(x[k]<=n)
        {
            if(k==n)
            {
                count++;
                printf("\n\tSolution %d  is : \n\n\n",count);
                print_solution(n,x);

            }
            else
            {
                k++;
                x[k]=0;
                 }
        }
        else
        {
            k--;
        }
    }
    return;
}


void main()
{
    int n;
    clock_t start,end;
    clrscr();
    start=clock();
    printf("\n Enter the no. of Queens : ");
    scanf("%d",&n);
    printf("\n\n\t\t\t USING %d QUEEN'S STRATEGY \n\n",n);
    nqueens(n);
    end=clock();
    printf("\n The Time Complexity is : %f msec.",(end-start)/CLK_TCK);
    getch();
}

Click Here to Download Source Code with Executable Program.

Leave a comment

Two Pass Assembler

C - Program to Implement Two Pass Assembler

 #include<conio.h>
#include<stdio.h>
#include<stdlib.h>
struct a
{
char b[10][10];
};

struct a source[10];
struct a symtab[10];
struct a littab[10];
struct a opcode[10];
struct a reg[10];
struct a decstate[3];
FILE *f1,*f2,*f3,*f4,*f5,*f6,*f7,*f8
;
int litcount,litlines,vari,prolines,w,x,symlines,reglines,oplines,loc,flag=0;
void main ()
{
int i,k=0,j,l,t,flag1=0;
char ch;
f1=fopen("source2.txt","r");
f2=fopen("symtab1.txt","w");
f3=fopen("opcodes.txt","r");
f5=fopen("literal.txt","w");
f4=fopen("register.txt","r");
f6=fopen("out2pass1.txt","w");
f7=fopen("error.txt","w");
f8=fopen("decstate.txt","r");
clrscr();
printf("\n source program \n");
while(!feof(f1))
{
    for(i=0;i<4;i++)
    {
        fscanf(f1,"%s",&source[k].b[i]);
        printf("%s",source[k].b[i]);
        printf("\t");
    }
    printf("\n");
    k++;
}




prolines=k;
getch();
clrscr();
loc=atoi(source[0].b[3]);
j=0;


k=0;
printf("\nDeclaration Statement\n");
while(!feof(f8))
{
    for(i=0;i<2;i++)
    {
        fscanf(f8,"%s",&decstate[k].b[i]);
        printf("%s",decstate[k].b[i]);
        printf("\t");
    }
    printf("\n");
    k++;
}




if(strcmp(source[0].b[1],"START")!=0)
{
fprintf(f7,"Invalid Start of program");
}
else
fprintf(f7,"");

for(i=0;i<prolines;i++)
    {
        if(strcmp(source[i].b[1],"END")==0)
        {
               flag=1;
        }
    }

if(flag==0)
    fprintf(f7,"\nInvalid End of Program");
else
    fprintf(f7,"");







printf("\n SYMBOL TABLE\n");
printf("SI.NO\tSYMBOL\tADDRESS\n");

for(i=0;i<23;i++)
{
    if(strcmp(source[i].b[0],"*")!=0)
    {
        j++;
        fprintf(f2,"%d\t%s\t%d",j,source[i].b[0],(loc+i)+1);
        printf("%d\t%s\t%d",j,source[i].b[0],(loc+i)+1);
        printf("\n");
        fprintf(f2,"\n");
    }
}

getch();
clrscr();
k=0;
printf("\n register table\n");

while(!feof(f4))
{
    for(i=0;i<2;i++)
    {
        fscanf(f4,"%s",reg[k].b[i]);
        printf("%s",reg[k].b[i]);
        printf("\t");
    }
    printf("\n");
    k++;
}
reglines=k;
getch();
clrscr();
k=0;
loc=atoi(source[0].b[3]);
    for(i=0;i<10;i++)
        if(strcmp(source[i].b[1],"LTORG")==0)
            litcount=loc+i+1;
        printf("\nliteral table\n");//literal table generation
        k=1;

    for(i=1;i<=prolines;i++)
        if(source[i].b[3][0]=='=')
        {
            fprintf(f5,"%d\t%s\t%d",k,source[i].b[3],litcount);
            printf("%d\t%s\t%d",k,source[i].b[3],litcount);
            k++;
            litcount++;
            printf("\n");
        }
    litlines=k-1;
    getch();
    clrscr();
    k=0;

printf("\n opcode table\n");
    while(!feof(f3))
    {
        for(i=0;i<2;i++)
        {
            fscanf(f3,"%s",&opcode[k].b[i]);
            printf("%s",opcode[k].b[i]);
            printf("\t");
        }
        printf("\n");
        k++;
    }
fclose(f3);
oplines=k;
f3=fopen("opcodes.txt","r");
for(l=0;l<23;l++)
    {
        flag1=0;
        for(t=0;t<19;t++)
        {
            if(strcmp(source[l].b[1],opcode[t].b[0])==0)
            {
               flag1=1;
               break;
            }
        }
            if(flag1==0)
                fprintf(f7,"\nInvalid opcode %d %s %s",l,source[l].b[1],opcode[t].b[0]);

    }




getch();
clrscr();
k=0;
fclose(f5);
f5=fopen("literal.txt","r");
    while(!feof(f5))
    {
        for(i=0;i<3;i++)
        {
            fscanf(f5,"%s",&littab[k].b[i]);
        }
        k++;
    }
fclose(f1);
fclose(f2);
fclose(f3);
fclose(f4);
fclose(f5);
fclose(f7);
f2=fopen("symtab1.txt","r");
k=0;
    while(!feof(f2)) //creation of symbol table struct
    {
        for(i=0;i<3;i++)
        {
        fscanf(f2,"%s",&symtab[k].b[i]);
        }
        k++;
    }
    symlines=k;
    fclose(f2);
    printf("\nintermediate code \n");
    fprintf(f6,"\nINTERMEDIATE CODE \n");
    ch=source[10].b[2][0];
    prolines=prolines+2;
    printf("(AD,00)\t\t(C,%s)\n",source[0].b[3]);
    fprintf(f6,"(AD,00)\t\t(C,%s)\n",source[0].b[3]);
for(i=1;i<=prolines;i++)//starting the creation of intermediate code
{
    w=x=0;
    if(strcmp(source[i].b[1],"DS")!=0 && strcmp(source[i].b[1],"DC")!=0 )
    {
        for(j=0;j<10;j++)
            if(strcmp(source[i].b[1],opcode[j].b[0])==0)
            {
                //vari=atoi(opcode[j].b[1]);
                printf("(IS,%s)\t",opcode[j].b[1]);
                fprintf(f6,"(IS,%s)\t",opcode[j].b[1]);
            }
    }
    if(strcmp(source[i].b[1],"DS")==0 || strcmp(source[i].b[1] ,"DC")==0 )
    {
        for(j=0;j<3;j++)
            if(strcmp(source[i].b[1],decstate[j].b[0])==0)
            {

                printf("(DL,%s)\t",decstate[j].b[1]);
                fprintf(f6,"(DL,%s)\t",decstate[j].b[1]);
            }
    } //finish of first column
    for(j=0;j<4;j++)
    {
        if(strcmp(source[i].b[2],reg[j].b[0])==0)
        {
            w=1;
            printf("(%s)\t",reg[j].b[1]);
            fprintf(f6,"(%s)\t",reg[j].b[1]);
        }
    }
    if(source[i].b[2][0]==ch) //where ch=" ' "
    {
        x=1;
        printf("\t(C,%c)\t",source[i].b[2][1]);
        fprintf(f6,"\t(C,%c)\t",source[i].b[2][1]);
    }
    if(w!=1 && x!=1 && strcmp(source[i].b[1],"LTORG")!=0)
    {
        printf("\t");
        fprintf(f6,"\t");
    }
    for(j=0;j<symlines;j++)
        if(strcmp(source[i].b[3],symtab[j].b[1])==0)
        {
            printf("(S,%d)",atoi(symtab[j].b[0]));
            fprintf(f6,"(S,%d)",atoi(symtab[j].b[0]));
        }
    if(source[i].b[3][0]=='=')
        for(j=0;j<3;j++)
            if(strcmp(source[i].b[3],littab[j].b[1])==0)
            {
                printf("(L,%s)",littab[j].b[0]);
                fprintf(f6,"(L,%s)",littab[j].b[0]);
            }
            if(strcmp(source[i].b[1],"LTORG")!=0)
            {
                printf("\n");
                fprintf(f6, "\n");
            }
    if(strcmp(source[i].b[1],"END")==0)
                printf("(AD,03)");
                fprintf(f6,"(AD,03)");


}
fclose(f8);
getch();
}

Click Here to Download Source Code with Executable Program

Leave a comment

Quick Sort

C - Program to Implement Quick Sort

 #include<iostream.h>
#include<conio.h>
#include<time.h>

class sort
{
   public:
   int a[100],n;
   int lo,hi;
   void get();
   void disp();
   void quicksort(int,int);
};

int main()
{
  int i;
  char k='y';
  sort a;

  do
  {
    clrscr();
    float toc;
    clock_t end,start;
    start=clock();
    cout<<"\n\t\t\t\tQuick Sort\n";
    cout<<"\t\t\t\t----------\n\n";
    a.get();
    cout<<"\n\t\t\t*** Array Before Sorting ***\n\n";
    a.disp();
    a.quicksort(a.lo,a.hi);
    cout<<"\n\n\n\t\t\t*** Array After Sorting ***\n\n";
    a.disp();
    end=clock();
    toc=(end - start)/CLK_TCK;
    cout<<"\n\tTime Complexity :: "<<toc;
    cout<<"\n\n\t\t\tDo you want to Continue?(y/n)";
    k=getche();
  }while(k=='y');
  return 0;
}


void sort::get()
{
  int i;
  cout<<"\n\tEnter Size of Array :: ";
  cin>>n;
  lo=0;
  hi=n-1;
  cout<<"\n\tEnter the Elements of Array :: ";
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
}


void sort::disp()
{
  int i;
  cout<<"\n\tElements of Array :: ";
  for(i=0;i<n;i++)
  {
    cout<<" "<<a[i];
  }
}

void sort::quicksort(int lo,int hi)
{
  int i,j,k,x;
  i=lo;
  j=hi;
  x=a[(lo+hi)/2];
  do
  {
    while(a[i]<x)
        i++;
    while(a[j]>x)
        j--;
    if(i<=j)
    {
    k=a[i];
    a[i]=a[j];
    a[j]=k;
    i++;
    j--;
    }
  }while(i<=j);
  if(lo<i-1)
    quicksort(lo,i-1);
  if(i<hi)
    quicksort(i,hi);
}

Click Here to Download Source Code with Executable Program.

Leave a comment

Merge Sort

C - Program to Implement Merge Sort


 #include<time.h>
#include<iostream.h>
#include<conio.h>

void mergesort(int *,int,int);
void merge(int *,int,int,int);
int a[20],i,n,b[20];
void get();
void disp();

main()
{
   int i;
   char k='y';
   do
   {
    clrscr();
    float toc;
    clock_t end,start;
    start=clock();
    cout<<"\n\t\t\t\tMerge Sort";
    cout<<"\n\t\t\t\t----------";
    get();
    cout<<"\n\n\t\t\t *** Before Sorting ***\n";
    disp();
    mergesort(a,0,n-1);
    cout<<"\n\n\t\t\t *** After Sorting ***\n";
    disp();
    end=clock();
    toc=(end - start)/CLK_TCK;
    cout<<"\n\n\tTime Complexity :: "<<toc;
    cout<<"\n\n\t\t\tDo u want to continue?(y/n)";
    k=getche();
   }while(k=='y'||k=='Y');
}

void get()
{
    int i;
    cout<<"\n\n\n\tEnter the Size of Array ::";
    cin>>n;
    cout<<"\n\tEnter the Elements of Array ::";
    for(i=0;i<n;i++)
    cin>>a[i];
}

void disp()
{
    int i;
    cout<<"\n\tElements of Array ::";
    for(i=0;i<n;i++)
    {
    cout<<" "<<a[i];
    }
}

void mergesort(int a[],int i,int j)
{
   int mid;
   if(i<j)
   {
      mid=(i+j)/2;
      mergesort(a,i,mid);
      mergesort(a,mid+1,j);
      merge(a,i,mid,j);
   }
}
void merge(int a[],int low,int mid ,int high)
{
   int h,i,j,k;
   h=low;
   i=low;
    j=mid+1;
   while(h<=mid && j<=high)
   {
      if(a[h]<=a[j])
     b[i]=a[h++];
      else
     b[i]=a[j++];
      i++;
   }

   if( h > mid)
      for(k=j;k<=high;k++)
    b[i++]=a[k];
   else
      for(k=h;k<=mid;k++)
     b[i++]=a[k];

   for(k=low;k<=high;k++)
   {
    a[k]=b[k];
   }

}

Click Here to Download Source Code with Executable Program.

Leave a comment

Macro Processor

C - Program to Implement Macro Processor


# include <stdio.h>
# include <conio.h>
# include <string.h>
# include <stdlib.h>
struct deftab
{
char lab[10];
char opc[10];
char oper[10];
}d[10];
void main()
{
char label[10],opcode[10],operand[10],newlabel[10],newoperand[10];
char macroname[10];
int i,lines;
FILE *f1,*f2,*f3;
clrscr();
f1=fopen("macin.txt","r");
f2=fopen("macout.txt","w");
f3=fopen("deftab.txt","w");
fscanf(f1,"%s%s%s",label,opcode,operand);
while(strcmp(opcode,"END")!=0)
{
if(strcmp(opcode,"MACRO")==0)
{
strcpy(macroname,label);
fscanf(f1,"%s%s%s",label,opcode,operand);
lines=0;
while(strcmp(opcode,"MEND")!=0)
{
fprintf(f3,"%s\t%s\t%s\n",label,opcode,operand);
strcpy(d[lines].lab,label);
strcpy(d[lines].opc,opcode);
strcpy(d[lines].oper,operand);
fscanf(f1,"%s%s%s",label,opcode,operand);
lines++;
}
}
else if(strcmp(opcode,macroname)==0)
{
printf("Lines = %d\n",lines);
for(i=0;i<lines;i++)
{
fprintf(f2,"%s\t%s\t%s\n",d[i].lab,d[i].opc,d[i].oper);
printf("DLAB = %s\nDOPC = %s\nDOPER = %s\n",d[i].lab,d[i].opc,d[i].oper);
}
}
else
fprintf(f2,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(f1,"%s%s%s",label,opcode,operand);
}
fprintf(f2,"%s\t%s\t%s\n",label,opcode,operand);
fclose(f1);
fclose(f2);
fclose(f3);
printf("FINISHED");
getch();
}

Click Here to Download Source Code with Executable Program.


Leave a comment

Lexical Analyzer

C Program to Implement Lexical Analyzer


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

char buffer[80];
int i,len,pos;
char token[30];
int ibuff;

void skip()
{
    for(;buffer[ibuff]==' '||buffer[ibuff]=='\t';ibuff++);
}

void insert(char *a,char x)
{
    int i;
    i=strlen(a);
    a[i]=x;
    a[i+1]=0;
}

char terminals[30][10]={{"{"},{"}"},{"("},{")"},{"if"},{"else"},{"while"},
            {"int"},{"char"},{"float"},{"="},{"=="},{"+"},{"-"},{"*"},{"/"},
            {"%"},{"<"},{"<="},{">"},{">="},{"!="},{"&&"},{"||"},{"!"},
            {";"},{"&"},{"|"},{"void"}};

char identifiers[20][20];
int iterminals=29;
int iidentifiers;
int literals[20];
int iliterals=0;

int searchterminals(char *a)
{
    for(i=0;i<iterminals;i++)
        if(strcmp(terminals[i],a)==0)
            return 1;
        return 0;
}

void printterminal(char *a)
{
    for(i=0;i<iterminals;i++)
        if(strcmp(terminals[i],a)==0)
        {
            printf("\n%10s TRM %d",a,i);
            return;
        }
}

void printliteral(char *a)
{
    int x;
    x=atoi(a);
    for(i=0;i<iliterals;i++)
        if(literals[i]==x)
            break;
        if(i==iliterals)
        {
            literals[i]=x;
            iliterals++;
        }
    printf("\n%10s LTS %d",a,i);
}
void printidentifier()
{
    int i=0;
    for(i=0;i<iidentifiers &&strcmp(token,identifiers[i])!=0;i++);
    if(i>=iidentifiers)
    {
        strcpy(identifiers[iidentifiers],token);
        iidentifiers++;
    }
    printf("\n%10s IDN %d",token,i);
pos=i;
}
int state;
void main()
{
FILE *ptr;
char infile[12];

clrscr();
printf("\n Enter source file name:");
gets(infile);
ptr=fopen(infile,"r");
if(ptr==NULL)
{
    printf("\n Could not open the file:");
    exit(0);
}
printf("\n Uniform symbol Table");
printf("\n______________________");
while(!feof(ptr))
{
    fgets(buffer,80,ptr);
    len=strlen(buffer);
    buffer[len]='\0';
    buffer[len+1]=0;
    ibuff=0;
    state=0;
    skip();
    for(;buffer[ibuff]!=0;ibuff++)
    {
        switch(state)
        {
        case 0:
        switch(buffer[ibuff])
        {
            case '#':
                printf("\npreprocessor directive:%s",buffer);
                ibuff=strlen(buffer)-1;
            break;
            case ' ':skip();ibuff--;break;
            case '"':
                token[0]=0;
                ibuff++;
                do
                {
                    insert(token,buffer[ibuff]);
                    ibuff++;
                }while(buffer[ibuff]!='"');
                printf("\n string  %s",token);
            break;
            case '\n':break;
            case '(':printterminal("(");break;
            case ')':printterminal(")");break;
            case '}':printterminal("}");break;
            case '{':printterminal("{");break;
            case ';':printterminal(";");break;
            case ',':printterminal(",");break;
            case '*':printterminal("*");break;
            case '/':printterminal("/");break;
            case '%':printterminal("%");break;
            case '+':state=70;break;
            case '-':state=80;break;
            case '=':state=90;break;
            case '!':state=100;break;
            case '<':state=110;break;
            case '>':state=120;break;
            case '|':state=130;break;
            case '&':state=140;break;
            default:
                if(isdigit(buffer[ibuff]))
                {
                    token[0]=0;
                    do
                    {
                        insert(token,buffer[ibuff]);
                        ibuff++;
                    }while(isdigit(buffer[ibuff]));
                    printliteral(token);
                    ibuff--;
                }
                else
                    if(isalpha(buffer[ibuff]))
                    {
                        token[0]=0;
                        do
                        {
                            insert(token,buffer[ibuff]);
                            ibuff++;
                        }while(isalnum(buffer[ibuff]));

                        if(searchterminals(token))
                            printterminal(token);
                        else
                            printidentifier();
                        ibuff--;
                    }
                    else
                    {
                        printf("\n unknown token=%s",buffer);
                        exit(0);
                    }
                    break;
                }

                break;

        case 70:if(buffer[ibuff]=='+')
                printterminal("++");
            else
            {
                printterminal("+");
                ibuff--;
            }
            state=0;
            break;
        case 80:if(buffer[ibuff]!='-')
                printterminal("-");
            else
            {
                printterminal("-");
                ibuff--;
            }
            state=0;break;
        case 90:if(buffer[ibuff]=='=')
                printterminal("==");
            else
            {
                printterminal("=");
                ibuff--;
            }
            state=0;break;
        case 100:if(buffer[ibuff]=='=')
                printterminal("!=");
            else
            {
                printterminal("!");
                ibuff--;
            }
            state=0;break;
        case 110:if(buffer[ibuff]=='=')
                printterminal("<=");
            else
            {
                printterminal("<");
                ibuff--;
            }
            state=0;break;
        case 120:if(buffer[ibuff]=='=')
                printterminal(">=");
            else
            {
                printterminal(">");
                ibuff--;
            }
            state=0;break;
        case 130:if(buffer[ibuff]=='|')
                printterminal("||");
            else
            {
                printterminal("|");
                ibuff--;
            }
            state=0;break;
        case 140:if(buffer[ibuff]=='&')
            printterminal("&&");
            else
            {    printterminal("&");
                ibuff--;
            }
            state=0;break;
        }
    }
}

printf("\n Press a key to print Symbol Table.....\n");
getch();
for(i=0;i<iidentifiers;i++)
    printf("\n %s",identifiers[i]);
printf("\n Pres a key to print Literal Table.......\n");
getch();
for(i=0;i<iliterals;i++)
    printf("\n%d",literals[i]);
getch();
}
/*

Input Program

#include<stdio.h>
#include<conio.h>
void str()
{
    int x=2,y=3,z;
    z=x+y;
}

Click Here to Download Source Code with Executable Program.

Leave a comment