首页 > 代码库 > 小小码屋
小小码屋
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define KEYSIZE 17
#define SYMBILESIZE 6
#define KEYWORLD 1
#define DEFINED 2
#define SYMBOL 3
#define ISCHARACTER ((97<=*str&&*str<=122)||(65<=*str&&*str<=90))
#define ISCHAR_NUM_UNDERLINE ((97<=*(str+i)&&*(str+i)<=122)||(65<=*(str+i)&&*(str+i)<=90)||(48<=*(str+i)&&*(str+i)<=57)||(*(str+i)==‘_‘))
//typedef struct{
// char definedname[10];
// int dataspecies;
// int pointspecies;
//}
typedef struct{
char keyname[10];
char keyexp[100];
}keyword;
char dealword[100];
keyword key[KEYSIZE]={
"char","字符型",
"int","整型",
"short","短整型",
"long","长整型",
"float","浮点型",
"double","双精度浮点型",
"signed","有符号的",
"unsigned","无符号的",
"auto","自动的",
"extern","全局的",
"static","静态的",
"typedef","别名",
"union","共用体",
"struct","结构体",
"enum","枚举体",
"void","无返回值或者无参或者无类型",
"*","指针",
};
char symbol[]={‘[‘,‘]‘,‘(‘,‘)‘,‘,‘,‘ ‘};
int issymbol(char c)
{
int i=0,flag=0;
while(i<SYMBILESIZE){
if(c==symbol[i]){
flag=i;
break;
}
i++;
}
return flag;
}
int isdefined(char *str)
{
int i=1;
if( ISCHARACTER ){
while(*(str+i)){
if(!ISCHAR_NUM_UNDERLINE){
printf("%s:标识符不合法\n",str);
return 0;
}
i++;
}
for(i=0;i<KEYSIZE;i++)
if(!strcmp(key[i].keyname,str)){
printf("%s:这是个关键字:%s\n",key[i].keyname,key[i].keyexp);
break;
}
if(i==KEYSIZE)
printf("%s:这是个标识符\n",str);
}
else{
printf("%s:标识符不合法\n",str);
return 0;
}
}
int readword(char *str,int i)
{
int n,j=0;
if(*(str+i)==‘\0‘)
return 0;
if((n=issymbol(*(str+i)))){
i++;
}
else{
for(;*(str+i)!=‘\0‘;i++){
if(!issymbol(*(str+i))){
dealword[j]=*(str+i);
j++;
}
else{
break;
}
}
isdefined(dealword);
memset(dealword,0,100);
}
readword(str,i);
}
int main(int argc,char **argv)
{
char *str="long fast bbc ok 999,union,oo34*@&#^!ok,bcnbads9";
readword(str,0);
}
小小码屋