IMPLEMENTATION OF TYPE CHECKING
AIM:
To write a C program to implement type
checking
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
PROGRAM CODE:
//To implement type checking
#include<stdio.h>
#include<stdlib.h>
int 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; } }
}
return 0;
}
OUTPUT:
you make it look so hard
ReplyDeleteThat's what she said
Deleteffs
DeleteFFS
DeleteThis is not me. My account is most likely compromised.
DeleteChi Samarth
DeleteStop lying Samarth Mayya
DeleteI'm not lying, you can see for yourself. The link to that guy's profile and my profile are different.
DeleteThank You maam
ReplyDeleteThis comment has been removed by the author.
Delete