// // Created by Administrator on 2021/4/30. // #ifndef SYNTAXPARSER_GRAMMARRESOURCEPOOL_H #define SYNTAXPARSER_GRAMMARRESOURCEPOOL_H #include #include #include #include #include // 语法资源池 class GrammarResourcePool { int pdt_index = 0; // 符号表 SymbolTable symbolTable; // 产生式 std::vector productions; // FIRST结果存储表 std::map *> firsts; // FOLLOW结果存储表 std::map *> follows; // 去掉首尾空格 static std::wstring& trim(std::wstring &&str) { if (str.empty()) { return str; } str.erase(0,str.find_first_not_of(' ')); str.erase(str.find_last_not_of(' ') + 1); return str; } public: const std::set *FIRST(const std::vector &symbols, int start_index); const std::set* FIRST(int symbol); const std::set *FOLLOW(int symbol); void FOLLOW(); std::set* get_follow_set(int symbol); void print_symbols(const std::set &symbols_index); void parse_production_string_line(const std::wstring &temp_line); [[nodiscard]] const std::vector &get_productions() const { return productions; } [[nodiscard]] const Symbol *getSymbol(int symbol_index) const { return symbolTable.getSymbol(symbol_index); } [[nodiscard]] const Symbol *getStartSymbol() const { return symbolTable.getStartSymbol(); } int addSymbol(const std::wstring &name, bool terminator) { return symbolTable.addSymbol(name, terminator); } const Production *addProduction(int left, std::initializer_list right); [[nodiscard]] const std::vector &getAllSymbols() const { return symbolTable.getAllSymbols(); } void modifySymbol(int index, const std::wstring &name, bool terminator, bool start) { symbolTable.modifySymbol(index, name, terminator, start); } [[nodiscard]] int getSymbolIndex(const std::wstring &name) const { return symbolTable.getSymbolIndex(name); } }; #endif //SYNTAXPARSER_GRAMMARRESOURCEPOOL_H