Symboltable
Symboltable
h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int size=0;
void Insert();
void Display();
void Delete();
int Search(char lab[]);void Modify();
struct SymbTab
{
char label[10],symbol[10];
int addr;
struct SymbTab *next;};
struct SymbTab *first,*last;
void main()
{
int op,y;
char la[10];
do
{
printf("\n-------------------------------------------------------------------------
-----------------------------------------------------------------------");
printf("\n\t\t\t\t\t\tSYMBOL TABLE MAIN MENU\n");
printf("---------------------------------------------------------------------------
---------------------------------------------------------------------");
printf("\n1.INSERT SYMBOL TABLE VALUES\n2.DISPLAY SYMBOL
TABLE\n3.SEARCH TABLE ENTRIES\n4.MODIFY TABLE ENTRIES\n5.EXIT TABLE VIEW\n");
printf("\nEnter your option : ");
scanf("%d",&op);
switch(op)
{
case 1:
Insert();
break;
case 2:
Display();
break;
case 3:
printf("\nEnter the label to be searched : ");
scanf("%s",la);
y=Search(la);
printf("\nSearch Result: ");
if(y==1)
printf("\nThe label is present in the symbol
table\n");
else
printf("\nThe label is not present in the symbol
table\n");
break;
case 4:
Modify();
break;
case 5:
exit(0);
}
}while(op<10);
getch();
}
void Insert()
{
int n;
char l[10];
if(size==0)
{
first=p;
last=p;
}
else
{
last->next=p;
last=p;
}
size++;
void Display()
{
int i;
struct SymbTab *p;
p=first;
printf("\nLABEL\tADDRESS\n");
for(i=0;i<size;i++)
{
printf("%s\t%d\n",p->label,p->addr);
p=p->next;
}
}
void Modify()
{
char l[10],nl[10];
int add,choice,i,s;
struct SymbTab *p;
p=first;
printf("\nEnter your modification choice : \n");
printf("\n1.Only the label\n2.Only the address\n3.Both the label and
address\n");
printf("\nEnter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nEnter the old label : ");
scanf("%s",l);
s=Search(l);
if(s==0)
printf("\nLabel not found\n");
else
{
printf("\nEnter the new label : ");
scanf("%s",nl);
for(i=0;i<size;i++)
{
if(strcmp(p->label,l)==0)
strcpy(p->label,nl);
p=p->next;
}
printf("\nAfter Modification:\n");
Display();
}
break;
case 2:
printf("\nEnter the label where the address is to be modified : ");
scanf("%s",l);
s=Search(l);
if(s==0)
printf("\nLabel not found\n");
else
{
printf("\nEnter the new address : ");
scanf("%d",&add);
for(i=0;i<size;i++)
{
if(strcmp(p->label,l)==0)
p->addr=add;
p=p->next;
}
printf("\nAfter Modification, THE DISPLAY IS: \n");
Display();
}
break;
case 3:
printf("\nEnter the old label : ");
scanf("%s",l);
s=Search(l);
if(s==0)
printf("\nLabel not found\n");
else
{
printf("\nEnter the new label : ");
scanf("%s",nl);
printf("\nEnter the new address : ");
scanf("%d",&add);
for(i=0;i<size;i++)
{
if(strcmp(p->label,l)==0)
{
strcpy(p->label,nl);
p->addr=add;
}
p=p->next;
}
printf("\nAfter Modification:\n");
Display();
}
break;
}
}