- 9
- 0
- 约3.82千字
- 约 12页
- 2018-01-02 发布于河南
- 举报
简单语法分析程序
#include stdio.h#include stdlib.h#include string.h#define _KEY_WORD_END waiting for your expandingtypedef struct { int typenum; char * word;} WORD;char input[255];char token[255]=;int p_input;int p_token;char ch;char* KEY_WORDS[]={begin,if,then,while,do,end,_KEY_WORD_END};WORD* scaner();void lrParser();void yucu();void statement();void statement();void expression();void term();void factor();int syn;int kk;WORD* oneword=new WORD;void main(){int over=1;printf(Enter Your words(end with #):);scanf(%[^#]s,input);p_input=0;printf(Your words:\n%s\n,input);oneword=scaner();lrParser();printf(\npress # to exit:);scanf(%[^#]s,input);}void lrParser(){if(syn==1){oneword=scaner();yucu();if(syn==6){oneword=scaner();if(syn==0kk==0){printf(%s,success);}else{if(kk!=1){printf(%s,缺end错误);kk=1;}}}}else{printf(%s,缺begin错误);kk=1;}}void yucu(){statement();while(syn==26){oneword=scaner();statement();}}void statement(){if(syn==10){oneword=scaner();if(syn==18){oneword=scaner();expression();}else{printf(%s,赋值号错误);kk=1;}}else{printf(%s,语句错误);kk=1;}}void expression(){term();while(syn==13||syn==14){oneword=scaner();term();}}void term(){factor();while(syn==15||syn==16){oneword=scaner();factor();}}void factor(){if(syn==10||syn==11){oneword=scaner();}else if(syn==27){oneword=scaner();expression();if(syn==28){oneword=scaner();}else{printf(%s,)错误);kk=1;}}else{printf(%s,表达式错误);kk=1;}}char m_getch(){ch=input[p_input];p_input=p_input+1;return (ch);}void getbc(){while(ch== ||ch==10){ch=input[p_input];p_input=p_input+1;}}void concat(){token[p_token]=ch;p_token=p_token+1;token[p_token]=\0;}int letter(){if(ch=ach=z||ch=Ach=Z)return 1;else return 0;}int digit(){if(ch=0ch=9)return 1;else return 0;}int reserve(){int i=0;while(strcmp(KEY_WORDS[i],_KEY_WORD_END)){if(!strcmp(KEY_WORDS[i],token)){return i+1;}i=i+1;}return 10;}void retract(){p_input=p_input-1;}char* dtb(){return NULL;}WORD* scaner(){WORD* myword=new WORD;myword-typenum=10;syn=myword-typenum;myword-word=;p_token=0;m_getch();getbc();if(letter()){wh
您可能关注的文档
最近下载
- 2024全国初中数学联赛初二卷 .pdf VIP
- 全国初中数学联合竞赛真题及答案(初二组)2015-年.pdf VIP
- AIAG-VDA-SPC手册-Yellow-Volume2026年2月第一版 中文.pdf VIP
- 美甲美睫投资回报2026年培训课件.pptx VIP
- 中国王氏家谱字辈大全.doc VIP
- 《Michael_Porter_Creating_Shared_Value》.pdf VIP
- 直播带货虚假宣传法律规制研究.pdf
- 新大洲本田MS01说明书用户手册.pdf
- 餐饮仓库进销存表格,感觉很实用的Excel表格,分享给大家.xls VIP
- (一模)新疆2026年高三普通高考二月适应性检测文科综合试卷.docx
原创力文档

文档评论(0)