标签:
#include<stdio.h>
void show(char ch[]);
void zimuma(char ch[]);
main()
{
char ch[100];
printf("请你输入一个源程序:");
gets(ch);
show(ch);
}
void show(char ch[])
{
int i,j=0,k=0;
int a[100];
char str[100]={NULL};
for(i=0;ch[i]!=‘\0‘;i++)
{
if((ch[i]==‘+‘)||(ch[i]==‘=‘)||(ch[i]==‘/‘)||(ch[i]==‘*‘)||(ch[i]==‘>=‘)||(ch[i]==‘<=‘)||(ch[i]==‘<‘)||(ch[i]==‘>‘))
switch(ch[i]){
case ‘+‘:printf("(2,%c)",ch[i]);printf("\n");break;
case ‘-‘:printf("(3,%c)",ch[i]);printf("\n");break;
case ‘*‘:printf("(4,%c)",ch[i]);printf("\n");break;
case ‘/‘:printf("(5,%c)",ch[i]);printf("\n");break;
case ‘<‘:printf("(6,%c)",ch[i]);printf("\n");break;
case ‘<=‘:printf("(7,%c)",ch[i]);printf("\n");break;
case ‘>‘:printf("(8,%c)",ch[i]);printf("\n");break;
case ‘>=‘:printf("(9,%c)",ch[i]);printf("\n");break;
case ‘=‘:printf("(11,%c)",ch[i]);printf("\n");break;
default:break;
}
else if((ch[i]>=32)&&(ch[i]<=41)||(ch[i]==‘.‘)||(ch[i]>=91&&ch[i]<=96)||(ch[i]==‘;‘)||(ch[i]==‘?‘))
//printf("(界符,%c)\n",ch[i]);
switch(ch[i]){
case ‘#‘:printf("(0,%c)",ch[i]);printf("\n");break;
case ‘;‘:printf("(12,%c)",ch[i]);printf("\n");break;
case ‘(‘:printf("(13,%c)",ch[i]);printf("\n");break;
case ‘)‘:printf("(14,%c)",ch[i]);printf("\n");break;
case ‘?‘:printf("(15,%c)",ch[i]);printf("\n");break;
case ‘.‘:printf("(16,%c)",ch[i]);printf("\n");break;
case ‘ ‘:printf("(17,%c)",ch[i]);printf("\n");break;
case ‘"‘:printf("(18,%c)",ch[i]);printf("\n");break;
case ‘,‘:printf("(19,%c)",ch[i]);printf("\n");break;
default:printf("(35,%c)",ch[i]);printf("\n");break;
}
else if(ch[i]>=48&&ch[i]<=57)
{
printf("(20,");//常数的种别码为28;
for(;(ch[i]>=48&&ch[i]<=57);i++)
{
printf("%c",ch[i]);//printf("%c",a[k]);
}
i--;
printf(")\n");}//memset(a,0,100);k=0;}
else
{
if((ch[i]>=‘a‘&&ch[i]<=‘z‘)||(ch[i]>=‘A‘&&ch[i]<=‘Z‘))
for(;((ch[i]>=‘a‘&&ch[i]<=‘z‘)||(ch[i]>=‘A‘&&ch[i]<=‘Z‘));i++,j++)
{
str[j]=ch[i];//printf("%c",str[j]);
}i--;
if(strcmp(str,"auto")==0|strcmp(str,"int")==0||strcmp(str,"do")==0||strcmp(str,"while")==0||
strcmp(str,"long")==0||strcmp(str,"short")==0||strcmp(str,"case")==0||(str,"switch")==0||
strcmp(str,"typedef")==0||(str,"const")==0||(str,"static")==0||strcmp(str,"double")==0||
strcmp(str,"char")==0||(str,"return")==0)
{
printf("(1,%s)\n",str);
memset(str,0,100); j=0;}
else
{//printf("(29,%s)\n",str);
printf("(10,%s)\n",str);
memset(str,0,100); j=0;}//清空数组;
}
}
}
标签:
原文地址:http://www.cnblogs.com/2439466501qq/p/5939438.html