IMPLEMENT TYPE CHECKING
AIM:
To write a C program to check whether the type of all variables in an expression are valid or not.
ALGORITHM:
Step1: Track the global scope type information (e.g. classes and their members)
Step2: Determine the type of expressions recursively, i.e. bottom-up, passing the resulting types
upwards.
Step3: If type found correct, do the operation
Step4: Type mismatches, semantic error will be notified
STEPS TO RUN C PROGRAM USING GCC COMPLIER:
1. Open any editor, type the needed C program and save as typecheck.c
2. Compile C language source
gcc typecheck.c
Following file will be generated : [Link]
3. Run the executable file : [Link]
#include<stdio.h>
void main()
int n,i,k,flag=0;
char vari[15],typ[15],b[15],c;
printf("Enter the number of variables:");
scanf(" %d",&n);
for(i=0;i<n;i++)
printf("Enter the variable[%d]:",i);
scanf(" %c",&vari[i]);
printf("Enter the variable-type[%d](float-f,int-i):",i);
scanf(" %c",&typ[i]);
if(typ[i]=='f')
flag=1;
}
printf("Enter the Expression(end with $):");
i=0;
getchar();
while((c=getchar())!='$')
b[i]=c;
i++;
k=i;
for(i=0;i<k;i++)
if(b[i]=='/')
flag=1;
break;
for(i=0;i<n;i++)
if(b[0]==vari[i])
if(flag==1)
if(typ[i]=='f')
printf("\nthe datatype is correctly defined..!\n");
break;
else
{
printf("Identifier %c must be a float type..!\n",vari[i]);
break;
else
printf("\nthe datatype is correctly defined..!\n");
break;