0% found this document useful (0 votes)
46 views3 pages

Token On

This program tokenizes the text from an input file by separating keywords, punctuation, operators, constants, and identifiers into different columns. It initializes graphics mode, opens the input file, reads each token and uses string comparison and conversion to determine the token type. It then prints the token into the corresponding column based on a switch statement before reading the next token, repeating until the end of file. The graphics mode is closed before the program ends.

Uploaded by

ramrajan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Token On

This program tokenizes the text from an input file by separating keywords, punctuation, operators, constants, and identifiers into different columns. It initializes graphics mode, opens the input file, reads each token and uses string comparison and conversion to determine the token type. It then prints the token into the corresponding column based on a switch statement before reading the next token, repeating until the end of file. The graphics mode is closed before the program ends.

Uploaded by

ramrajan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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();
}

You might also like