#include <stdio.h> #include <stdlib.h> #include <string.h> char prog[100],ch,token[8]; int p=0,syn,n,i; char *keyword[6]={"begin","then","if","while","do","end"}; void scaner(); void Irparse(); void statement(); void expression_r(); void term(); void factor(); void main() { int select=-1; p=0; printf("please input sentence, end of '#' ! "); do { ch=getchar(); prog[p++]=ch; }while(ch!='#'); p=0; printf("请输入1 或 2 1.词法分析 2.语法分析 "); scanf("%d",&select); if(select==1) { do { scaner(); switch(syn) { case -1:printf("词法分析 出错 ");break; default :printf("<%d,%s> ",syn,token);break; } }while(syn!=0); printf("词法分析 成功 "); } else if(select==2) { scaner(); if(syn==1) {Irparse();}//begin else {printf("语法分析出错! 请检查begin关键字 ");return;} if(syn==6)//end { scaner(); if(syn==0) { printf("恭喜 语法分析 成功 "); } else {printf("语法分析出错! 请检查是否缺少'#' ");} } else{printf("语法分析出错! 请检查是否缺少'end' ");} } getchar(); } void scaner() { for(n=0;n<8;n++) {token[n]='