_XiaoJuer_ 2021-07-03 14:56 采纳率: 0%
浏览 16

求解:编译原理 LL(1)文法例题

已知文法:G(S):
S -> a A S b ① | B d ②
A -> c S ③ | ε ④
B -> b B ⑤ | d ⑥
(1)求选择集合;证明是LL(1)文法;
(2)构造 LL(1)分析表。

  • 写回答

1条回答 默认 最新

  • 外星喵 2021-07-03 16:01
    关注

    #include
    #ifndef MAXNUM
    #define MAXNUM 100
    #endif
    #ifndef _STRUCT_H
    #define _STRUCT_H

    /数据定义/
    struct rule
    { //一个文法
    std::string startSymbol; //开始符号
    std::string tuidao; //推导式
    };

    struct record{ //记录一个终结符号由那些产生式得出的
    int num=0; //数量
    int gramNum[MAXNUM]; //产生式的编号
    };

    struct set
    { //集合
    char startSymbol; //非终结符
    char set[MAXNUM]; //frist or follow集合
    record gramNum[MAXNUM]; //记录一个终结符号是由哪些文法推导出的
    int num = 0;
    bool isExistE = false; //是否存在空串
    };

    struct tableCell{ //预测分析表的一个单元
    int num=0;
    rule cell[MAXNUM];
    bool error=true;
    };

    #endif

    #include "getFirFol.h"
    #include "struct.h"

    #ifndef _LL_H
    #define _LL_H

    class LL{
    public:
    LL(getFirst_Follow *ff,std::string ts, std::string nts, std::string rl);
    /构造分析表/
    void fillInTheTable();
    /分析字符串/
    void analyzeChars(std::string path);
    /在对应的分析表单元格加入文法/
    bool addInTableCell(int h,int l,int gramNum);
    private:
    getFirst_Follow *getff;
    std::string terSymbol; //终结符号集合
    int tsLength=0; //终结符号数量
    std::string nonTerSymbol; //非终结符号集合
    int ntsLength=0; //非终结符号数量
    rule *grammer = NULL; //文法
    int gramNum = 0; //文法公式数目
    tableCell **analyzeTable; //预测分析表
    bool isLLGrammer=true; //判断是为LL(1)文法
    };

    #endif

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用