Anna University Results November - December 2011 available with your GPA only for Credit System

Exam Results 2012

Exam Results 2012 Inspirational Quotes

Friday, September 17, 2010

Hi Friends .....

This is My New Blogs Subscribe to get the Updates on your mail  ......


Updates coming Soon .....

Tuesday, September 14, 2010

Symbol Table Using Hashing

/* IMPLEMENTATION OF SYMBOL TABLE USING HASHING */

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 10
char l[10];
struct symb
{
int add;
char label[10];
}sy[11];                                                          
void search();
void main()
{
int a[MAX],num,key,i,ch;
char ans;
int create(int);
void lprob(int[],int,int);
void display(int[]);
clrscr();
for(i=0;i<MAX;i++)
sy[i].add=-1;
do
{
printf("\nEnter your choice:1.create a symbol table\n2.exit");
scanf("%d",&ch);
switch(ch)
{
case 1:
do
{
printf("\nEnter the address :");
scanf("%d",&num);
key=create(num);
printf("Enter the label:");
scanf("%s",l);
lprob(a,key,num);
printf("\ncontinue(y/n)?");
ans=getche();
}
while(ans=='y');
display(a);
break;
case 2:
exit(0);
}}while(ch<=2);
getch();
}
int create(int num)
{
int key;
key=num%10;
return key;
}
void lprob(int a[MAX],int key,int num)
{
int flag,i,count=0;
void display(int a[]);
flag=0;
if(sy[key].add==-1)
{
a[key]=num;
sy[key].add=num;
strcpy(sy[key].label,l);
}
else
{
i=0;
while(i<MAX)
{
if(sy[i].add!=-1)
count++;
i++;
}
if(count==MAX)
{
printf("\nHash table is full");
display(a);
getch();
exit(1);
}
for(i=key+1;i<MAX;i++)
if(sy[i].add==-1)
{
a[i]=num;
flag=1;
sy[i].add=num;
strcpy(sy[i].label,l);
break;
}
for(i=0;i<key&&flag==0;i++)
if(sy[i].add==0)
{
a[i]=num;
flag=1;
sy[key].add=num;
strcpy(sy[key].label,l);
break;
}}}
void display(int a[MAX])
{
FILE *fp;
int i;
fp=fopen("symbol.txt","w");
printf("\nThe symbol Table is");
printf("\nHashvalues\taddress label");
for(i=0;i<MAX;i++)
{
printf("\n%d\t%d\t%s",i,sy[i].add,sy[i].label);
fprintf(fp,"\n%d%d%s",i,sy[i].add,sy[i].label);
}
fclose(fp);
}


// OUTPUT

Enter your choice
1.create a symbol table
2.exit
1

Enter the address :0
Enter the label:a

continue(y/n)?y
Enter the address :4
Enter the label:f

continue(y/n)?y
Enter the address :5
Enter the label:g

continue(y/n)?y
Enter the address :5
Enter the label:k

continue(y/n)?n
The symbol Table is
Hashvalues      address label
0       0       a
1       -1
2       -1
3       -1
4       4       f
5       5       g
6       5       k
7       -1
8       -1
9       -1
Enter your choice
1.create a symbol table
2.exit
2

If any flaws Contact to M.Baran Mahamood

Single Pass Macro Processor


/* Macro Processor */

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
int m=0,i,j,flag=0;
char c,*s1,*s2,*s3,*s4,str[50]=" ",str1[50]=" ";
char mac[10][10];
void main()
{
FILE *fpm=fopen("macro.txt","r");
FILE *fpi=fopen("minput.txt","r");
FILE *fpo=fopen("moutput.txt","w");
clrscr();
while(!feof(fpm))
{
fgets(str,50,fpm);
s1=strtok(str," ");
s2=strtok(NULL," ");
if(strcmp(s1,"MACRO")==0)
{
strcpy(mac[m],s2);
m++;
}
s1=s2=NULL;
}
fgets(str,50,fpi);
while(!feof(fpi))
{
flag=0;
strcpy(str1,str);
for(i=0;i<m;i++)
{
if(strcmp(str1,mac[i])==0)
{
rewind(fpm);
while(!feof(fpm))
{
fgets(str,50,fpm);
s2=strtok(str," ");
s3=strtok(NULL," ");
if(strcmp(s2,"MACRO")==0&&strcmp(s3,str1)==0)
{
fgets(str,50,fpm);
strncpy(s4,str,4);
s4[4]='\0';
while(strcmp(s4,"MEND")!=0)
{
fprintf(fpo,"%s",str);
printf("\n####%s",str);
fgets(str,50,fpm);
strncpy(s4,str,4);
s4[4]='\0';
}
}
}
flag=1;
break;
}
}
if(flag==0)
{
fprintf(fpo,"%s",str);
printf("%s",str);
}
fgets(str,50,fpi);
}
fclose(fpm);
fclose(fpi);
fclose(fpo);
getch();
}

Input Files : 

Macro.txt

MACRO ADD1
MOV A,B
ADD C
MEND
MACRO SUB1
STORE C
MEND

MInput.txt

MOV B,10
MOV C,20
ADD1
MUL C
SUB1
END

MOutput.txt

MOV B,10
MOV C,20
MOV A,B
ADD C
MUL C
STORE C
END


If any flaws Contact to M.Baran Mahamood