资源简介

本程序为编译原理语法分析程序,内含源代码和报告,以供参考!

资源截图

代码片段和文件信息

#include “stdio.h“                  /*定义I/O库所用的某些宏和变量*/
#include “string.h“                 /*定义字符串库函数*/
#include “conio.h“                  /*提供有关屏幕窗口操作函数*/
#include “ctype.h“                  /*分类函数*/


char prog[80]={‘\0‘}
     token[8];                     /*存放构成单词符号的字符串*/
char ch;
int syn                           /*存放单词字符的种别码*/
      n
     kk
    sum                           /*存放整数型单词*/
    mp;                           /*p是缓冲区prog的指针,m是token的指针*/
char *rwtab[6]={“begin““if““then““while““do““end“};


void scaner()
{
    m=0;
    sum=0;

    for(n=0;n<8;n++)
        token[n]=‘\0‘;

    ch=prog[p++];

    while(ch==‘ ‘)
        ch=prog[p++];

    if(isalpha(ch))    /*ch为字母字符*/
    {
        while(isalpha(ch)||isdigit(ch))    /*ch 为字母字符或者数字字符*/
        {
           token[m++]=ch;
           ch=prog[p++];
        }

        token[m++]=‘\0‘;
        ch=prog[p--];
        syn=10;

        for(n=0;n<6;n++)
            if(strcmp(tokenrwtab[n])==0)    /*字符串的比较*/
            {
                syn=n+1;
                break;
            }
    }
    else
        if(isdigit(ch))    /*ch是数字字符*/
        {
            while(isdigit(ch))    /*ch是数字字符*/
            {
                sum=sum*10+ch-‘0‘;
                ch=prog[p++];
            }

            ch=prog[p--];
            syn=11;
        }
        else
            switch(ch)
            {
                case‘<‘:m=0;
                        token[m++]=ch;
                        ch=prog[p++];

                        if(ch==‘>‘)
                        {
                            syn=21;
                            token[m++]=ch;
                        }

                        else if(ch==‘=‘)
                        {
                            syn=22;
                            token[m++]=ch;
                        }

                             else
                             {
                                 syn=20;
                                 ch=prog[p--];
                             }
                        break;

                case‘>‘:m=0;
                        token[m++]=ch;
                        ch=prog[p++];

                        if(ch==‘=‘)
                        {
                            syn=24;
                            token[m++]=ch;
                        }

                        else
                        {
                            syn=23;
                            ch=prog[p--];
                        }
                        break;

             case‘:‘:m=0;
                     token[m++]=ch;
                     ch=prog[p++];

                     if(ch==‘=‘)
                     {
                         syn=18;
                         token[m++]=ch;
                     }

                     else
                     {
                         syn=17;
                         ch=prog[p--];
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6116  2008-06-01 21:52  yufafenxi.c

     文件      77312  2008-06-13 18:47  语法分析程序报告0.doc

----------- ---------  ---------- -----  ----

                83428                    2


评论

共有 条评论