微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 声明转文字: 编写程序将C语言的声明转换为文字描述

声明转文字: 编写程序将C语言的声明转换为文字描述

时间:11-22 来源:互联网 点击:

temp[0] = \0;

gettoken();

do {

if (tokentype != NAME) {

prevtoken = YES;

dcl();

} else if (typespec() == YES) {

strcat(temp, " ");

strcat(temp, token);

gettoken();

} else if (typequal() == YES) {

strcat(temp, " ");

strcat(temp, token);

gettoken();

} else

errmsg("unknown type in parameter list\n");

} while (tokentype != , && tokentype != ));

strcat(out, temp);

if (tokentype == ,)

strcat(out, ",");

}

int typespec(void)

{

static char *types[] = {"char", "int", "void"};

char *pt = token;

if (bsearch(&pt, types, sizeof(types)/sizeof(char *), sizeof(char *), compare) == NULL)

return NO;

else

return YES;

}

int typequal(void)

{

static char *typeq[] = {"const", "volatile"};

char *pt = token;

if (bsearch(&pt, typeq, sizeof(typeq)/sizeof(char *), sizeof(char *), compare) == NULL)

return NO;

else

return YES;

}

int compare(char **s, char **t)

{

return strcmp(*s, *t);

}

三.程序小结

1. 程序缺陷

当输入 int a(

输入不了了 为什么呢?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top