0% found this document useful (0 votes)
39 views4 pages

Symboltable

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Symboltable

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

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];

printf("\nEnter the label : ");


scanf("%s",l);
n=Search(l);
if(n==1)
printf("\nThe label exists already in the symbol table\nDuplicate values
cannot be inserted");
else
{
struct SymbTab *p;
p=malloc(sizeof(struct SymbTab));
strcpy(p->label,l);

printf("\nEnter the address : ");


scanf("%d",&p->addr);
p->next=NULL;

if(size==0)
{
first=p;
last=p;
}
else
{
last->next=p;
last=p;
}
size++;

printf("\nLabel for Symbol Table Inserted\n");


}
}

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;
}
}

int Search(char lab[])


{
int i,flag=0;
struct SymbTab *p;
p=first;
for(i=0;i<size;i++)
{
if(strcmp(p->label,lab)==0)
flag=1;
p=p->next;
}
return flag;
}

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;
}
}

You might also like