user-0 提问: 求助用C程序对给定文法进行递归下降分析问题

回复:
user: user-0
content: 谢谢帮助，问题解决了

user: user-1
content: #include <stdio.h> #include<dos.h> #include<stdlib.h> #include<string.h> char v[50], u[50], d[200], e[10]; char ch; int n1, i1 = 0, flag = 1, n = 7; int S(); int M(); int T(); int N(); void input(); void input1(); void output();  //================================================ int main()                      /*递归分析*/ {     int f, p, j = 0;     char x;     d[0] = 'S';     d[1] = '=';     d[2] = ' ';     d[3] = '(';     d[4] = 'T';     d[5] = ')';     d[6] = '#';      printf("请输入字符串(长度<50,以#号结束）\n");     do {         scanf("%c", &ch);         v[j] = ch;         j++;     } while (ch != '#');      n1 = j;     ch = u[0] = v[0];     printf("文法\t分析串\t\t分析字符\t剩余串\n");     f = S();     if (f == 0)         return -1;     if (ch == '#') {         printf("accept\n");         p = 0;         x = d[p];         while (x != '#') {             printf("%c", x);             p = p + 1;             x = d[p];        /*输出推导式*/         }     } else {         printf("error\n");         printf("回车返回\n");         getchar();         getchar();         return -1;     }     printf("\n");     printf("回车返回\n");     getchar();     getchar(); }   //================================================ int S() {     int f;     if (ch == '(') {         u[i1] = ch;         printf("S->(T)\t");         e[0] = 'S';         e[1] = '=';         e[2] = ' ';         e[3] = '(';         e[4] = 'T';         e[5] = ')';         e[6] = '#';         output();         flag = 0;         input();         input1();         ch = v[++i1];         f = T();         if (f == 0)             return (0);         if (ch == ')') {             u[i1] = ch;             printf("S--(T)\t");             flag = 0;             input();             input1();             ch = v[++i1];         } else {             printf("error\n");             return (0);         }      }     if (ch == 'a') {         u[i1] = ch;         printf("S->aM\t");         e[0] = 'S';         e[1] = '=';         e[2] = ' ';         e[3] = 'a';         e[4] = 'M';         e[5] = '#';         output();         flag = 0;         input();         input1();         ch = v[++i1];         f = M();         if (f == 0)             return (0);         return (1);     } else {         printf("error\n");         return (0);     }     return (1); }  //================================================ int T() {     int f, t;     printf("T->SN\t");     e[0] = 'T';     e[1] = '=';     e[2] = ' ';     e[3] = 'S';     e[4] = 'N';     e[5] = '#';     output();     flag = 1;     input();     input1();     f = S();     if (f == 0)         return (0);     t = N();     if (t == 0)         return (0);     else         return (1); }  //================================================ int N() {     int f, t;     if (ch == 'b') {         u[i1] = ch;         printf("N->bSN\t");         e[0] = 'N';         e[1] = '=';         e[2] = ' ';         e[3] = 'b';         e[4] = 'S';         e[5] = 'N';         e[6] = '#';         output();         flag = 0;         input();         input1();         ch = v[++i1];         f = S();         if (f == 0)             return (0);         t = N();         if (t == 0)             return (0);         else             return (1);     }      printf("N->^\t");     e[0] = 'N';     e[1] = '=';     e[2] = ' ';     e[3] = '^';     e[4] = '#';     output();     flag = 1;     v[i1] = ch;     input();     input1();     return (1);  } //================================================   int  M() {     int f;     if (ch == '+') {         u[i1] = ch;         printf("M->+S\t");         e[0] = 'M';         e[1] = '=';         e[2] = ' ';         e[3] = '+';         e[4] = 'S';         e[5] = '#';         output();         flag = 0;         input();         input1();         ch = v[++i1];         f = S();         if (f == 0)             return (0);         return (1);     }     printf("M->^\t");     e[0] = 'M';     e[1] = '=';     e[2] = ' ';     e[3] = '^';     e[4] = '#';     output();     flag = 1;     input();     input1();     return (1); }  //================================================  void input() {     int j = 0;     for (; j <= i1 - flag; j++)         printf("%c", u[j]);               /*输出分析串*/      printf("\t\t");     printf("%c\t\t", ch);                 /*输出分析字符*/ }  //================================================ void input1() {     int j;     for (j = i1 + 1 - flag; j < n1; j++)         printf("%c", v[j]);                /*输出剩余字符*/      printf("\n"); }    //================================================ void output()                               /*推导式计算*/ {     int m, k, j, q;     int i = 0;     m = 0;     k = 0;     q = 0;     i = n;     d[n] = '=';     d[n + 1] = ' ';     d[n + 2] = '#';     n = n + 2;     i = n;     i = i - 2;     while (d[i] != ' ' && i != 0)         i = i - 1;     i = i + 1;     while (d[i] != e[0])         i = i + 1;     q = i;     m = q;     k = q;     while (d[m] != ' ')         m = m - 1;     m = m + 1;     while (m != q) {         d[n] = d[m];         m = m + 1;         n = n + 1;     }     d[n] = '#';     for (j = 3; e[j] != '#'; j++) {         d[n] = e[j];         n = n + 1;     }     k = k + 1;     while (d[k] != '=') {         d[n] = d[k];         n = n + 1;         k = k + 1;     }     d[n] = '#'; }   这样可以编译，

user: user-0
content: 对文法使用了递归下降分析方法，手残打错了。。