复杂声明
来源:互联网 发布:写程序的软件 编辑:程序博客网 时间:2024/05/01 00:01
#include <stdio.h>#include <string.h>#include <ctype.h>#define MAXTOKEN 100enum{NAME,PARENS,BRACKETS};void dcl(void);void dirdcl(void);int gettoken(void);int tokentype;char token[MAXTOKEN];char name[MAXTOKEN];char datatype[MAXTOKEN];char out[100];int main(){while(gettoken()!='%'){strcpy(datatype,token);out[0]='\0';dcl();if(tokentype!='\n')printf("syntax error\n");printf("%s %s %s\n",name,out,datatype);}return 0;}void dcl(void){int ns;for(ns=0;gettoken()=='*';)//ns++;dirdcl();while(ns-->0)//printf("1");strcat(out,"pointer to");}void dirdcl(void){int type;if(tokentype=='('){dcl();if(tokentype!=')')printf("error:missing)\n");}else if(tokentype==NAME){strcpy(name,token);}else{printf("error:expected name or(dcl)\n");}while((type=gettoken())==PARENS||type==BRACKETS)if(type==PARENS){strcat(out,"function returning");}else{strcat(out,"array");strcat(out,token);strcat(out,"of");}}int gettoken(void){int c,getch(void);void ungetch(int);char *p=token;while((c=getch())==' '||c=='\t');if(c=='('){if((c=getch())==')'){strcpy(token,"()");return tokentype=PARENS;}else{ungetch(c);return tokentype='(';}}else if(c=='['){for(*p++=c;(*p++=getch())!='[';);*p='\0';return tokentype=BRACKETS;}else if(isalpha(c)){for(*p++=c;isalnum(c=getch());){*p++=c;}*p='\0';ungetch(c);return tokentype=NAME;}else{return tokentype=c;}}#define BUFSIZE 100char buf[BUFSIZE];int bufp=0;int getch(void){return (bufp>0)?buf[--bufp]:getchar();}void ungetch(int c){if(bufp>=BUFSIZE){printf("ungetch:too many characters\n");}else{buf[bufp++]=c;}}
0 0
- 复杂声明
- 复杂声明
- 复杂声明
- C复杂声明解析
- C复杂声明解析
- 指针 复杂的声明
- C++复杂声明
- C复杂声明解析
- C复杂声明
- 解读复杂指针声明
- 复杂声明分析
- C语言复杂声明
- C语言复杂声明
- 指针 复杂的声明
- C复杂声明解析
- 指针的复杂声明
- 复杂指针的声明
- 如何解读复杂声明
- Qt入门之常用qt控件认知之Button系列
- Struts2中的ModelDriven机制及其运用
- 哈弗曼编码译码系统
- LeetCode 013. Roman to Integer
- bluez蓝牙协议栈交叉编译移植教程
- 复杂声明
- 本人大一的课程设计,时间太长,代码可能有些许丢失,欢迎纠错
- IOS中UILabel常见属性及UILabel自适应高度和自动换行
- Linux 通过lseek()来实现文件大小的设置
- Cts框架解析(22)-自动检测设备
- 指针的咨询,求解答????
- 大数据——hadoop1.2.1+hbase0.94.11+nutch2.2.1+elasticsearch0.90.5安装配置(上集)
- 复杂声明的语法进行了简化
- pc寄存器与可寻址空间