码迷,mamicode.com
首页 > 其他好文 > 详细

实验三、 递归下降分析程序实验

时间:2016-12-18 01:56:20      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:scanf   表达   ring   log   strcpy   nbsp   class   sha   bsp   

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
char s[10];   
int x=0;
void A();          
void B();           
void C();          
void D(); 
void E();
 
int main()
{
    int len;
    printf("请输入算术表达式:(以#为结束)\n");
    scanf("%s",s);
    len=strlen(s);
    s[len]=‘#‘;
    s[len+1]=‘\0‘;
    A();
    printf("True!\n");
    strcpy(s,"");
    x=0;
    return 0;
}
 
void A()
{
    C();
    B();
}
 
void B()
{
    if(s[x]==‘+‘||s[x]==‘-‘)
    {
        x++;
        C();
        B();
    } 
}
 
void C()
{
    E();
    D();
}
 
void D()
{
    if(s[x]==‘*‘||s[x]==‘/‘)
    {
        x++;
        E();
        D();
    }
}
 
void E()
{
    if(s[x]>=‘a‘&&s[x]<=‘z‘)
    {
        x++;
    }
    else if(s[x]>=0&&s[x]<=9)
    {
        x++;
    }
    else if (s[x]==‘(‘)
    {     
        x++;
        A();
        if(s[x]==‘)‘)
        {
            x++; 
        }
        else
        {
            printf("Error!\n");
            exit(0);
        }
    } 
    else
    {
        printf("Error!\n"); 
        exit(0);
    }
}

 

实验三、 递归下降分析程序实验

标签:scanf   表达   ring   log   strcpy   nbsp   class   sha   bsp   

原文地址:http://www.cnblogs.com/170he/p/6193259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!