#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
int i=0,g;
char ch,st[10];
clrscr();
fp=fopen("i.c","r");
while((ch=getc(fp))!=EOF)
printf("%c",ch);
rewind(fp);
printf("\n\n");
while((ch=getc(fp))!=EOF)
{
if(isalpha(ch)||isdigit(ch)||ch=='.'||ch=='['||ch=='_')
{
st[i]=ch;
i++;
g=i;
if(ch=='[')
{
while((ch=getc(fp))!=']')
{
st[i]=ch;
i++;
}
st[i]=']';
i++;
st[i]='\0';
printf("%s\t array identifier",st);
if(isdigit(st[g+1]))
{
if(isdigit(st[g+1])&&isdigit(st[i-2]))
printf("\n");
else
printf("\t----->error\n");
}
else
printf("\n");
i=0;
continue;
}
}
else
{
st[i]='\0';
if(strcmp(st,"if")==0||strcmp(st,"then")==0||strcmp(st,"while")==0||strcmp(st,"for")==0)
{
printf("%s\t keyword \n",st);
i=0;
st[i]='\0';
}
if(strcmp(st,"int")==0||strcmp(st,"float")==0||strcmp(st,"char")==0||strcmp(st,"double")==0)
{
printf("%s\t datatype\n",st);
i=0;
st[i]='\0';
}
else
{
if(isspace(ch))
{
i=0;
continue;
}
if(isdigit(st[0]))
printf("%s\t constant\n",st);
if(st[0]!='\0'&&isalpha(st[0]))
printf("%s\t identifier\n",st);
i=0;
}
if(ch=='=')
{
ch=getc(fp);
if(ch=='=')
printf("==\t relational operator\n");
else
{
printf("=\tassignment operator\n");
st[i]=ch;
i++;
}
}
if(ch==';'||ch==',')
printf("%c\t special symbol\n",ch);
else if(ch=='('||ch==')'||ch=='{'||ch=='}')
printf("%c\t special symbol\n",ch);
else if(ch=='*'||ch=='/')
printf("%c\t arithmetic operator\n",ch);
else if(ch=='+'||ch=='-')
{
st[i]=ch;
i++;
ch=getc(fp);
if(ch=='+')
{
st[i]=ch;
i++;
st[i]='\0';
printf("%s\tincrement operator\n",st);
i=0;
continue;
}
if(ch=='-')
{
st[i]=ch;
i++;
st[i]='\0';
printf("%s\tdecrement operator\n",st);
i=0;
continue;
}
if(ch=='=')
{
st[i]=ch;
i++;
st[i]='\0';
printf("%s\t shorthand operator\n",st);
i=0;
continue;
}
else
{
printf("%s\t arithmetic operator\n",st);
i=0;
st[i]=ch;
i++;
st[i]='\0';
}
}
if(ch=='>'||ch=='<')
{
st[i]=ch;
i++;
ch=getc(fp);
if(ch=='=')
{
st[i]=ch;
i++;
st[i]='\0';
printf("%s\t relational operator\n",st);
i=0;
}
else
{
printf("%s\t relational operator\n",st);
i=0;
st[i]=ch;
i++;
st[i]='\0';
}
}
}
}
//rewind(fp);
//fclose(fp);
getch();
}
OUTPUT:
a++;a--;double a[10];if(a==10);a=a+1;a+=1;
a identifier
++ increment operator
; special symbol
a identifier
-- decrement operator
; special symbol
double datatype
a[10] array identifier
; special symbol
if keyword
( special symbol
a identifier
== relational operator
10 constant
) special symbol
; special symbol
a identifier
= assignment operator
a identifier
+ arithmetic operator
1 constant
; special symbol
a identifier
+= shorthand operator
1 constant
; special symbol
********************************
MORE:
->GIVE ADS
->EARN MONY
->DOWNLOADS(softwares,wallpapers,etc)
(CLICK THE PICTURE BELOW)
JOB VIRUS |
No comments:
Post a Comment