12.16

10598 단어
/*G[E]:
E->E+T|E-T|T
T->T*F|T/F|F
F->(E)|i
 
E->TE'
E'->+TE'|-TE'|ε
T->FT'
T'->*FT'|/FT'|ε
F->(E)|i
*/
#include<stdio.h>
char sym;
char LL1[1000];
int N=-1;

void T();
void E();
void F();
void e();
void t();
void error();
void scaner();
void main()
{
    char ch;
    int i=0;
    printf(" sym :( # )
"); do{ scanf("%c",&ch); LL1[i] = ch; i++; }while(ch != '#'); scaner(); E(); if(sym == '#') printf("
"); else{ printf(" !!
"); error(); } } void scaner(){ // N++; if(LL1[N] == ' '){ N++; }else{ sym = LL1[N]; } } void E(){ T(); e(); } void T(){ F(); t(); } void e(){ if(sym == '+'||sym == '-'){ scaner(); T(); e(); } else if(LL1[N+1] == '#' || LL1[N+1] == '+' || LL1[N+1] == '/' || LL1[N+1] == '*' || LL1[N+1] == '-'){ if(LL1[N] != '(' && LL1[N] != ')') error(); } } void t(){ if(sym == '*'||sym == '/'){ scaner(); F(); T(); } else if(LL1[N+1] == '#' || LL1[N+1] == '+' || LL1[N+1] == '/' || LL1[N+1] == '*' || LL1[N+1] == '-'){ if(LL1[N] != '(' && LL1[N] != ')') error(); } } void F(){ if(sym == '('){ scaner(); E(); if(sym == ')'){ scaner(); }else{ error(); } }else // while(1){ if(sym >= 'a' && sym<='z' || sym >= 'A' && sym <= 'Z' || sym >= '0' && sym <= '9'){ scaner(); } else{ break; } } } void error(){ printf(" %d %c !
",N,sym); }

좋은 웹페이지 즐겨찾기