编译原理(递归下降分析程序)

来源:互联网 发布:qq飞车网络环境异常 编辑:程序博客网 时间:2024/06/05 08:50

编译原理 (递归下降分析程序)

 #include<iostream>#include<string>#include<stdlib.h>using namespace std;int i=0;string nexttoken;char ch;void A();void A1();void read(){      ch= nexttoken[++i];}void error(){      cout<<"不是本文法的句型!!"<<endl;      exit(1);}                                   void S(){      read();      if(ch=='(')      {             read();             A();                          if (ch==')') goto L;             else error();      }      else  if(ch!='a') error();      else { read();A();      if(ch=='b') goto L;      else error();}L:read(); return;  }void A(){      if(ch== 'e') {read();goto L;}      if(ch!= 'd') error();      S();L:A1(); return; }void A1(){L:if(ch=='d'){ read();goto L;} else if(ch=='b') goto L1; else if(ch==')') goto L1; else error();L1:return;  }void main(){      try      {             cout<<"Please input the string: "<<endl;             cin>>nexttoken;             ch=nexttoken[i];             S();             cout<<"为本文法的句型!"<<endl;      }      catch(char)      {             cout<<"输入出错!"<<endl;      }}//(aeb)正确 


原创粉丝点击