// // Created by Administrator on 2021/4/30. // #ifndef SYNTAXPARSER_SYNTAXPARSER_H #define SYNTAXPARSER_SYNTAXPARSER_H #include #include #include #include #include #include #include class SyntaxParser { // 文件输入 std::wifstream input; std::wofstream output; std::wofstream treeOutput; const GrammarResourcePool *pool; const AnalyseTableGenerator *atg; std::queue tokens_queue; std::stack analyse_stack; std::stack status_stack; std::stack tree_stack; std::vector lines_index; std::wstringstream string_buffer; size_t now_line = 1; static std::vector ws_split(const std::wstring& in, const std::wstring& delim); static std::pair get_token_info(const std::wstring &token); SyntaxTree syntaxTree; public: SyntaxParser(const GrammarResourcePool *pool, const AnalyseTableGenerator *atg): input("tokenOut.txt", std::ios::binary), pool(pool), atg(atg), output("AnalyseOut.txt", std::ios::binary), treeOutput("SyntaxOut.txt", std::ios::binary){ auto* codeCvtToUTF8= new std::codecvt_utf8; input.imbue(std::locale(input.getloc(), codeCvtToUTF8)); output.imbue(std::locale(output.getloc(), codeCvtToUTF8)); treeOutput.imbue(std::locale(output.getloc(), codeCvtToUTF8)); } ~SyntaxParser() { input.close(); output.close(); treeOutput.close(); } // 得到所有的产生式 void getToken(); void printSymbol(int symbol_index); void printProduction(const Production *p_pdt); // 自底向上语法分析 void parse(); void printError(std::wofstream &errOutput); void printError(); void printDone(); }; #endif //SYNTAXPARSER_SYNTAXPARSER_H