• 0916 词法分析第二次作业


    #include<stdio.h>

    #include <string.h>

    #include<iostream.h>

    main(){

        char a[200];

        char cf,bf;

        int i,b;

        b=0;

        printf("请输入字符(输入#结束):");

        do

        {

             scanf("%c",&cf);

             a[b++]=cf;

        }while(cf!='#');

        for(i=0;i<b;i++)

        {

            bf=a[i];

            if(bf>='a'&&cf<='z')

            {

                if(a[i]=='b'&&a[i+1]=='e'&&a[i+2]=='g'&&a[i+3]=='i'&&a[i+4]=='n')

                {

                    printf("<1,begin > ");

                i=i+4;

                continue;

                }

                else if(a[i]=='i'&&a[i+1]=='f')

                {

                    printf("<2,if > ");

                i=i+1;

                continue;

                }

                else if(a[i]=='t'&&a[i+1]=='h'&&a[i+2]=='e'&&a[i+3]=='n')

                {

                    printf("<3,then > ");

                i=i+3;

                continue;

                }

                else if(a[i]=='w'&&a[i+1]=='h'&&a[i+2]=='i'&&a[i+3]=='l'&&a[i+4]=='e')

                {

                    printf("<4,while > ");

                i=i+4;

                continue;

                }

                else if(a[i]=='d'&&a[i+1]=='o')

                {

                    printf("<5,do > ");

                i=i+1;

                continue;

                }

                else if(a[i]=='e'&&a[i+1]=='n'&&a[i+2]=='d')

                {

                    printf("<6,end > ");

                i=i+2;

                continue;

                }

                else if(a[i]=='l'&&a[i+1]=='('&&a[i+2]=='l'&&a[i+3]=='|'&&a[i+4]=='d'&&a[i+5]==')'&&a[i+6]=='*')

                {

                    printf("<10,l(l|d)* > ");

                i=i+6;

                continue;

                }

                else if(a[i]=='d'&&a[i+1]=='d'&&a[i+2]=='*')

                {

                    printf("<11,dd* > ");

                i=i+2;

                continue;

                }

            }

            if(bf==':')

                if(a[i+1]=='='){

                    printf("<18,:= > ");

                    i=i+1;

                    continue;}

             if(bf=='<')

                if(a[i+1]=='='){

                    printf("<21,<= > ");

                    i=i+1;

                    continue;}

             if(bf=='<')

                if(a[i+1]=='>'){

                    printf("<22,<> > ");

                    i=i+1;

                    continue;}

             if(bf=='>')

                if(a[i+1]=='='){

                    printf("<24,>= > ");

                    i=i+1;

                    continue;}

            switch(bf)

            {

            case '+':

                printf("<13,%c > ",bf);

                break;

             case '-':

                printf("<14,%c > ",bf);

                break;

             case '*':

                printf("<15,%c > ",bf);

                break;

             case '/':

                printf("<16,%c > ",bf);

                break;

             case ':':

                printf("<17,%c > ",bf);

                break;

             case '(':

                printf("<27,%c > ",bf);

                break;

             case ')':

                printf("<28,%c > ",bf);

                break;

             case '#':

                printf("<0,%c > ",bf);

                break;

             case '>':

                printf("<23,%c > ",bf);

                break;

             case '<':

                printf("<20,%c > ",bf);

                break;

             case ';':

                printf("<26,%c > ",bf);

                break;

            }

        }

    }

  • 相关阅读:
    树形dp--P2014 [CTSC1997]选课
    背包变形--P1759 通天之潜水
    区间dp--P1880 [NOI1995]石子合并
    动态规划--P2758 编辑距离
    筛法--CF449C Jzzhu and Apples
    BZOJ3998: [TJOI2015]弦论(后缀自动机,Parent树)
    BZOJ3530: [Sdoi2014]数数(Trie图,数位Dp)
    BZOJ1444: [Jsoi2009]有趣的游戏(Trie图,矩乘)
    BZOJ1195: [HNOI2006]最短母串(Trie图,搜索)
    BZOJ3238: [Ahoi2013]差异(后缀数组)
  • 原文地址:https://www.cnblogs.com/huang123/p/4825881.html
Copyright © 2020-2023  润新知