Sie sind auf Seite 1von 3

Token Seperation

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
struct str
{
char a[100];
}s;
void main()
{
FILE *fp;
i
nt j,f=0,flag,gd,gm;
char q[15][15]={"(",")","{","}","[","]","#","!","&",",",".",":",";","?",'"'};
char r[15][15]={"+","-","*","/","%","<",">","="};
char p[15]
[15]={"stdio.h","void","main","math.h","conio.h","string.h","graphics.h","int","char",
"float","printf","scanf","include"};
clrscr();
gd=DETECT;
initgraph(&gd,&gm,"\\Turboc3\\bgi");
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,475);
gotoxy(3,4);
printf("Keywords");
gotoxy(14,4);
printf("Punctuation");
gotoxy(28,4);
printf("Operators");
gotoxy(40,4);
printf("Constants");
gotoxy(53,4);
printf("Identifiers");
fp=fopen("add.c","r");
f=5;
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();
}

Das könnte Ihnen auch gefallen