Code Monkey home page Code Monkey logo

implementation-of-symbol-table-'s Introduction

Ex-2 IMPLEMENTATION OF SYMBOL TABLE

NAME:MANO M

REGISTER NUMBER:212221040100

DATE:14.02.2024

AIM :

To write a C program to implement a symbol table.

ALGORITHM

  1. Start the program.
  2. Get the input from the user with the terminating symbol ‘$’.
  3. Allocate memory for the variable by dynamic memory allocation function.
  4. If the next character of the symbol is an operator then only the memory is allocated.
  5. While reading, the input symbol is inserted into symbol table along with its memory address.
  6. The steps are repeated till ‘$’ is reached.
  7. To reach a variable, enter the variable to be searched and symbol table has been checked for corresponding variable, the variable along with its address is displayed as result.
  8. Stop the program.

PROGRAM

#include<stdio.h>
#include<conio.h> 
#include<ctype.h> 
#include<malloc.h> 
#include<string.h> 
#include<math.h>
void main()
{
int i=0,j=0,x=0,n,flag=0; void *p,*add[5];
char ch,srch,b[15],d[15],c; 
printf("Enter the Expression terminated by $: ");
while((c=getchar())!='$')
{
b[i]=c; i++;
}
n=i-1;
printf("Given Expression:"); i=0;
while(i<=n)
{
printf("%c",b[i]); i++;
}
printf("\n Symbol Table\n"); printf("Symbol\taddr\ttype"); while(j<=n)
{
c=b[j]; if(isalpha(toascii(c)))
{
if(j==n)
{
p=malloc(c); add[x]=p;
d[x]=c;
printf("%c\t%d\tidentifier",c,p);
}
else
{
ch=b[j+1];
if(ch=='+'||ch=='-'||ch=='*'||ch=="=")
{
p=malloc(c); add[x]=p;
d[x]=c; printf("\n%c\t%d\tidentifier\n",c,p); x++;
}}} j++;
}
printf("\n The symbol is to be searched"); srch=getch();
for(i=0;i<=x;i++)
{
if(srch==d[i])
{
printf("\n Symbol Found"); printf("\n%c%s%d\n",srch,"@address",add[i]); flag=1;
}
}
if(flag==0)
printf("\nSymbol Not Found"); 
getch();
}

OUTPUT

image

RESULT

The program to implement a symbol table is executed and the output is verified.

implementation-of-symbol-table-'s People

Contributors

manomadhivanan avatar ramachandransec avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.