Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

ex no:2

date:3/1/19 Implementation of symbol table

aim:

to write a program in c to perform implementation of symbol table.

procedure:

• define the symbol table.


• scan the input program file word by word.
• check if there are any declarations.
• if any declarations present in the program check if it is already present in the symbol..
• if so then display the error message.
• else store the details of the declaration in the symbol table.
program:
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<string.h>
struct symbol
{
char label[10];
int size;
char type[10];
long addr;
struct symbol * next;
}
struct symbol *head;

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

You might also like