What is symbol table?
- 1. Walchand Institute of Technology
Seminar On
Symbol Table Genearation
Presented by……
Name
Shikha
Gajul Pooja
Kingi Kavita
NamaBabita
Pobatti Vaishali
- 2. What is Symbol Table ?
The compiler has to identifier used in source program.
It has to collect information about them like storage allocation for an identifier
it’s type, scope where in program they are valid and
in procedure name information about the :
Type of its argument,
Method of passing of this arguments ,
Type returned.
All this is stored in data structure called Symbol Table.
A symbol table is a necessary component because
Declaration of identifiers appears once in a program
Use of identifiers may appear in many places of the program text
- 3. USE OF SYMBOL TABLE
Symbol table information is used by the analysis and synthesis
phases.
To verify that used identifiers have been defined (declared).
To verify that expressions and assignments are semantically
correct – type checking.
To generate intermediate or target code.
- 4. #include<stdio.h>
#include<conio.h>
#include<string.h>
void check_var();
FILE *fp;
char ch;
int i,j,k,m,ptr;
char *str1[]={"int","float","char"};
void main()
{
char *word;
clrscr();
printf("ntData type tLengthttSymbolttAddress");
fp=fopen("c:turboc3s.c","r");
if(fp==NULL)
{
printf("nCan't open a file.");
return;
}
- 5. while((ch=fgetc(fp))!=EOF)
{
i=0;
*word=NULL;
while((ch!='n')&(ch!=' ')&(ch!=EOF))
{
word[i]=ch;
ch=fgetc(fp);
i++;
}
m=strlen(word);
if(m!=i)
{
word[i]='0';
}
for(k=0;k<3;k++)
{
ptr=strcmp(&(str1[k][0]),word);
if(ptr==0)
check_var(word);
}
}
getch();
}
- 6. void check_var(char *word)
{
char word1[10];
int n;
ch=fgetc(fp);
while((ch!=';')&&(ch!='n')&&(ch!=EOF))
{
printf("nnt");
fputs(word,stdout);
if(k==0)
fputs("tt2 bytes",stdout);
else if(k==1)
fputs("tt4 bytes",stdout);
else if(k==2)
fputs("tt1 byte ",stdout);
n=0;