• 工程代码结构说明——哈工大编译原理课程(五)


     

    main.c          语法分析器与中间代码生成器,它调用词法分析器

    token_analyze   词法分析器

    queue.h         队列

    stack.h         栈

    linklist.h      链表

    data_struct.h   Token数据结构

    FourElemFormula 四元式相关,如四元式的数据结构、打印(到文件)函数、释放四元式内存行数

    • operator.h      四元式的第一个运算符宏定义

    symboltable.h   符号表管理

    debug.h         打印符号表

    table.h         bison生成的预测分析表

    code.txt                                        Pascal源代码文件

    进行其他文件的测试时将token_analyze.h文件中void ReadFile()函数中的pfile = fopen

    ("code.txt", "r");改成其他文件名即可

    程序用到的部分数据结构

    a)   栈:后进先出

    b)   队列:先进先出

    c)   Token:符号栈中的元素

    typedef struct{

        int symbolnum;      //符号编号

        int type;         //type index_listxiao

        char name[64];     //id36

        int i;          //int37 width index_listda

        float f;        //float38

        char s[1027];        //string39

        struct idnode *addr;        //赋值语句的翻译时用

        struct idnode *offset;      //赋值语句的翻译时用

    }To;

    typedef To* Token;

    Token的属性域除了包含符号编号外,还包括保存词法分析器分析出来的值如常数、实数、字符串、id名等,另外的addr和offset用于赋值语句的翻译,其他域在特定符号时也会有不同的用处

    d)   Identifier:哈希表的节点

    typedef struct idnode{          /*哈希表的节点*/

        char name[64];

        int type;   /*类型,如int、int*等*/

        int offset;

        int *arrayex;

        struct idnode *next_hash;       /*指向下一节点的指针*/

    }Identifier;

    e)   Subproc:子过程条目

    typedef struct{               

        char name[64];

        struct symtable* s;

    }Subproc;

    f)   symtbl:符号表

    typedef struct symtable{                    

    struct symtable* before;

        int width;

        Identifier *SymbolTable[PRIME];    //哈希表,存放变量

        Subproc *SubprocArray[SUBPROC_NUM];

        int subprocptr;

    }symtbl;

     出错处理:

    能处理编译过程中的词法错误并提示、定位

    能处理语法错误、变量没有声明的语义错误。

  • 相关阅读:
    Python3爬虫系列:理论+实验+爬取妹子图实战
    虚机安装后无网卡、网卡驱动
    Linux运维工程师面试题整理
    睡眠或者重启windows,无法ssh连接或者pingVMware的虚机
    W10: Warning: Changing a readonly file使用vi/vim报错问题解决
    keyboard-interactive authentication with the ssh2 server failed 的SecureCRT报错解决
    公网访问内网实现(内网穿透)
    Linux内网时钟同步问题(ntp和chrony)
    xshell的快捷复制粘贴设置
    Linux中shell去除空行的几种方法
  • 原文地址:https://www.cnblogs.com/zhouliyan/p/5941770.html
Copyright © 2020-2023  润新知