Token Separation Source code c programming CS342 Compiler Lab

Algorithm Source Token Separation Source code C Programming
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
struct str
{
char a[30];
}s;
void main()
{
FILE *fp;
int j,f=0,flag,gd,gm;

char p[15][15]={"stdio.h","include","main","math.h","string.h",
"graphics.h","void","int","float","char"};
char q[15][15]={"(",")","[","]","{","}",":",".","#",";",",","?"};
char r[15][15]={"+","-","*","/","<",">","%","="};
gd=DETECT;
initgraph(&gd,&gm,"");
gotoxy(28,2);
printf("Token Seperation");
rectangle(3,35,530,475);
rectangle(3,35,100,475);
rectangle(200,35,300,475);
rectangle(300,35,400,475);
rectangle(3,35,530,75);
gotoxy(3,4);
printf("KEYWORDS");
gotoxy(16,4);
printf("PUNCT.SYMS");
gotoxy(28,4);
printf("OPERATORS");
gotoxy(40,4);
printf("CONSTANTS");
gotoxy(53,4);
printf("IDENTIFIERS");
fp=fopen("add.c","r");
f=7;
do
{
fscanf(fp,"%s",s.a);
for(j=0;j<=15;j++)
{
if(strcmp(s.a,p[j])==0)
flag=0;
}
for(j=0;j<=15;j++)
{
if(strcmp(s.a,q[j])==0)
flag=1;
}
for(j=0;j<=15;j++)
{
if(strcmp(s.a,r[j])==0)
flag=2;
}
if(atoi(s.a)>0||atoi(s.a)<0)
flag=3;
printf("\n");
switch(flag)
{
case 0:
gotoxy(5,f);
printf("%s",s.a);
break;
case 1:
gotoxy(17,f);
printf("%s",s.a);
break;
case 2:
gotoxy(29,f);
printf("%s",s.a);
break;
case 3:
gotoxy(41,f);
printf("%s",s.a);
break;
default:
gotoxy(53,f);
printf("%s",s.a);
}
f++;
flag=-1;
}while(!feof(fp));
getch();
closegraph();
}
Token Separation Algorithm Source CS342 Compiler Lab

Input File: add.c

void main ( )
{
int x = 6 ;
int y = 4 ;
x = x + y ;
}

Related post