Professional Documents
Culture Documents
Ex No:2 Date:3/1/19 Implementation of Symbol Table
Ex No:2 Date:3/1/19 Implementation of Symbol Table
aim:
procedure:
void display();
void insert();
S.Viveka
16CSE97
void main()
{
struct symbol *s=malloc(sizeof (struct symbol));
s->next=NULL;
int choice;
clrscr();
do
{
printf(“1.insert 2.display 3.exit”);
printf(“Enter your choice:”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
insert();
display();
break;
case 2:
display();
break;
default:
break;
}
}while(choice<3);
getch();
}
void insert()
S.Viveka
16CSE97
{
int n,*size;
char i[10];
printf(“enter the identifier:”);
scanf(“%s”,&i);
struct symbol *s=malloc(sizeof (struct symbol));
strcpy(s->label,i);
if(isalnum(i))
{
s->size=2;
strcpy(s->type,”int”);
}
else
{
s->size=1;
strcpy(s->type,”char”);
)
s->addr=&i;
s->next=null;
size++;
}
void display()
{
int i;
struct symbol *s=head;
printf(“Label \t Type \t Size \t MemoryAddress”);
for(i=0;i<size;i++)
S.Viveka
16CSE97
{
printf(“%s %s %d %d”,s->label,s->type,s->size,s->addr);
s=s->next;
}
}
output:
result:
Thus the program to implement symbol table management has been done successfully and the
output is verified
S.Viveka
16CSE97