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

Symbol Table in C++

The document discusses creating a symbol table for an expression by parsing the characters and storing identifiers and operators in an array along with their memory addresses. It prompts the user for an expression, prints the symbol table, then prompts for a symbol to search for and checks if it exists in the table.

Uploaded by

MAryam Khan
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 views2 pages

Symbol Table in C++

The document discusses creating a symbol table for an expression by parsing the characters and storing identifiers and operators in an array along with their memory addresses. It prompts the user for an expression, prints the symbol table, then prompts for a symbol to search for and checks if it exists in the table.

Uploaded by

MAryam Khan
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/ 2

#include "stdafx.

h"
#include "conio.h"
#include "string.h"
#include "ctype.h"
#include "stdlib.h"
#include <iostream>
#include <malloc.h>
#include <math.h>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{int i=0,j=0,x=0,n,flag=0; void *p,*add[15];
char ch,srch,b[15],d[15],c;
cout <<"expression terminated by $:";
while((c=getchar())!='$')
{
b[i]=c; i++;
}
n=i-1;
cout<<"given expression:";
i=0;
while(i<=n)
{
cout<<b[i];
i++;
}
cout <<"symbol table\n";
cout <<"symbol\taddr\ttype\n";
while(j<=n)
{
c=b[j];
if(isalpha(toascii(c)))
{
if(j==n)
{
p=malloc(c);
add[x]=p;
d[x]=c;
cout<<c<<p<<"\tidentifier\n";
}
else
{
ch=b[j+1];
if(ch=='+'||ch=='-'||ch=='*'||ch=='=')
{
p=malloc(ch);
add[x]=p;
d[x]=ch;
cout<<ch<<p<<"\tidentifier\n";
x++;
}
}
} j++;
}
cout<<"the symbol is to be searched\n";
srch=getch();
for(i=0;i<=x;i++)
{
if(srch==d[i])
{
cout<<"symbol found\n";
cout<<srch<<"@address"<<add[i]<<"\n";
flag=1;
}
}
if(flag==0)
cout<<"symbol not found\n";
return 0;
getche();
}

You might also like