WAP to incorporate a Symbol Table.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<io.h>
void main()
{
int i,j,k,l;
char ch[100],*p;
clrscr();
printf(" Enter the Statment:");
gets(ch);
printf("\n\nThe Statment For Which You Want To Make The Symbol Table is:");
puts(ch);
printf("\n\n\tGenerated Symbol Table \t ");
printf("\n----------------------------------------------------------------")
;
printf("\n Datatype \tVariable name \tVariable value \tAddress");
l=strlen(ch);
printf("\n");
printf("\n");
for(i=0;i<l;i++)
{
if(ch[i]=='i'&&ch[i+1]=='n')
{
printf("Int");
printf("\t\t%c",ch[i+4]);
printf("\t\t%c",ch[i+6]);
p=&ch[i+4];
printf("\t\t%u",p);
printf("\n\n");
k=i+7;
if(ch[k]==',')
{
printf("Int");
printf("\t\t%c",ch[k+1]);
printf("\t%c",ch[k+3]);
p=&ch[k+1];
printf("\t\t%u",p);
printf("\n");
}
}
if(ch[i]=='f'&&ch[i+1]=='l')
{
printf("float");
printf("\t\t%c",ch[i+6]);
printf("\t%c%c%c",ch[i+8],ch[i+9],ch[i+10]);
p=&ch[i+6];
printf("\t\t%u",p);
printf("\n");
k=i+11;
if(ch[k]==',')
{
printf("float");
printf("\t\t%c",ch[k+6]);
printf("\t%c%c%c",ch[k+8],ch[k+9],ch[k+10]);
p=&ch[k+6];
printf("\t\t%u",p);
printf("\n");
}
}
if(ch[i]=='c'&&ch[i+1]=='h')
{
printf("char");
printf("\t\t%c",ch[i+4]);
printf("\t%c%c",ch[i+6],ch[i+8]);
p=&ch[i+4];
printf("\t\t%u",p);
printf("\n");
k=i+8;
if(ch[k]==',')
{
printf("char");
printf("\t\t%c",ch[k+1]);
printf("\t%c%c",ch[k+3],ch[k+4]);
p=&ch[k+2];
printf("\t\t%u",p);
printf("\n");
}
}
}
getch();
}
#include<conio.h>
#include<string.h>
#include<io.h>
void main()
{
int i,j,k,l;
char ch[100],*p;
clrscr();
printf(" Enter the Statment:");
gets(ch);
printf("\n\nThe Statment For Which You Want To Make The Symbol Table is:");
puts(ch);
printf("\n\n\tGenerated Symbol Table \t ");
printf("\n----------------------------------------------------------------")
;
printf("\n Datatype \tVariable name \tVariable value \tAddress");
l=strlen(ch);
printf("\n");
printf("\n");
for(i=0;i<l;i++)
{
if(ch[i]=='i'&&ch[i+1]=='n')
{
printf("Int");
printf("\t\t%c",ch[i+4]);
printf("\t\t%c",ch[i+6]);
p=&ch[i+4];
printf("\t\t%u",p);
printf("\n\n");
k=i+7;
if(ch[k]==',')
{
printf("Int");
printf("\t\t%c",ch[k+1]);
printf("\t%c",ch[k+3]);
p=&ch[k+1];
printf("\t\t%u",p);
printf("\n");
}
}
if(ch[i]=='f'&&ch[i+1]=='l')
{
printf("float");
printf("\t\t%c",ch[i+6]);
printf("\t%c%c%c",ch[i+8],ch[i+9],ch[i+10]);
p=&ch[i+6];
printf("\t\t%u",p);
printf("\n");
k=i+11;
if(ch[k]==',')
{
printf("float");
printf("\t\t%c",ch[k+6]);
printf("\t%c%c%c",ch[k+8],ch[k+9],ch[k+10]);
p=&ch[k+6];
printf("\t\t%u",p);
printf("\n");
}
}
if(ch[i]=='c'&&ch[i+1]=='h')
{
printf("char");
printf("\t\t%c",ch[i+4]);
printf("\t%c%c",ch[i+6],ch[i+8]);
p=&ch[i+4];
printf("\t\t%u",p);
printf("\n");
k=i+8;
if(ch[k]==',')
{
printf("char");
printf("\t\t%c",ch[k+1]);
printf("\t%c%c",ch[k+3],ch[k+4]);
p=&ch[k+2];
printf("\t\t%u",p);
printf("\n");
}
}
}
getch();
}
Output:
Comments
Post a Comment