• 1223递归


    #include<stdio.h>
    char curr;
    char LL1[1000];
    int N=-1;
    
    void Top();
    void Top1();
    void Top2();
    void top();
    void top1();
    void error();
    void scaner();
    
    void main()
    {    char ch;
        int i=0;
        printf("请输入需要分析的curr语法:(以#结束)
    ");
        do{
            scanf("%c",&ch);
            LL1[i] = ch;
            i++;
        }while(ch != '#');
        scaner();
        Top1();
        if(curr == '#')
            printf("成功!
    ");
        else{
            printf("文法有误!!
    ");
            error();
        }
    
    }
    
    void scaner(){   //用于读取源函数的下一个字符
    
        N++;
        if(LL1[N] == ' '){
            N++;
        }else{
            curr = LL1[N];
        }
    }
    
    void Top(){
        Top2();
        top();
    }
    
    void Top1(){
        Top();
        top1();
    }
    
    void Top2(){
        if(curr == '('){
            scaner();
            Top1();
            if(curr == ')'){
                scaner();
            }
    		else
    		{
                error();
    		}
    		else
    		{
            //判断是否是函数或者是数字
            while(1){
                if(curr >= 'a' && curr<='z' || curr >= 'A' && curr <= 'Z' || curr >= '0' && curr <= '9'){
                    scaner();
                }
    			else
    			{
                    break;
                }
            }
        }
    }
    
    void top(){
        if(curr == '*'){
            scaner();
            Top2();
            Top();
        }else if(curr == '/'){
            scaner();
            Top2();
            Top();
        }else if(LL1[N+1] == '#' || LL1[N+1] == '+' || LL1[N+1] == '/' || LL1[N+1] == '*' || LL1[N+1] == '-'){
            if(LL1[N] != '(' && LL1[N] != ')')
            error();
        }
    }
    
    void top1(){
        if(curr == '+'){
            scaner();
            Top();
            top1();
        }
        else if(curr == '-'){
            scaner();
            Top();
            top1();
        }else if(LL1[N+1] == '#' || LL1[N+1] == '+' || LL1[N+1] == '/' || LL1[N+1] == '*' || LL1[N+1] == '-'){
            if(LL1[N] != '(' && LL1[N] != ')')
            error();
        }
    }
    
    void error(){
        printf("%d %c之后的文法有错!
    ",N,curr);
    }
    

      

  • 相关阅读:
    oracle omf管理 and asm omf
    oracle 9i下载地址
    rac部署过程的任务列表
    oracle connect实例
    cpio.gz文件解压缩方式
    函数remove_constants
    oracle优化日记脚本
    查看oracle隐含参数
    rac笔记
    MotionEvent的getX(),getY()与getRawX(),getRawY()区别
  • 原文地址:https://www.cnblogs.com/hanqilin/p/5070735.html
Copyright © 2020-2023  润新知