SyntaxParser/include/SyntaxParser.h

93 lines
1.9 KiB
C
Raw Normal View History

2021-04-30 12:55:56 +00:00
//
// Created by Administrator on 2021/4/30.
//
#ifndef SYNTAXPARSER_SYNTAXPARSER_H
#define SYNTAXPARSER_SYNTAXPARSER_H
#include <queue>
#include <stack>
#include <regex>
#include <codecvt>
#include <GrammarResourcePool.h>
#include <AnalyseTableGenerator.h>
2021-05-12 11:53:20 +00:00
#include <SyntaxTree.h>
2021-04-30 12:55:56 +00:00
class SyntaxParser {
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
std::wifstream input;
std::wofstream output;
2021-05-12 11:53:20 +00:00
std::wofstream treeOutput;
2021-04-30 12:55:56 +00:00
const GrammarResourcePool *pool;
const AnalyseTableGenerator *atg;
std::queue<int> tokens_queue;
std::stack<int> analyse_stack;
std::stack<int> status_stack;
2021-05-12 11:53:20 +00:00
std::stack<TreeNode *> tree_stack;
2021-04-30 12:55:56 +00:00
std::vector<size_t> lines_index;
std::wstringstream string_buffer;
size_t now_line = 1;
static std::vector<std::wstring> ws_split(const std::wstring& in, const std::wstring& delim);
static std::pair<std::wstring, std::wstring> get_token_info(const std::wstring &token);
2021-05-12 11:53:20 +00:00
SyntaxTree syntaxTree;
2021-04-30 12:55:56 +00:00
public:
SyntaxParser(const GrammarResourcePool *pool, const AnalyseTableGenerator *atg):
input("tokenOut.txt", std::ios::binary),
pool(pool),
atg(atg),
2021-05-12 11:53:20 +00:00
output("AnalyseOut.txt", std::ios::binary),
treeOutput("SyntaxOut.txt", std::ios::binary){
2021-04-30 12:55:56 +00:00
auto* codeCvtToUTF8= new std::codecvt_utf8<wchar_t>;
input.imbue(std::locale(input.getloc(), codeCvtToUTF8));
output.imbue(std::locale(output.getloc(), codeCvtToUTF8));
2021-05-12 11:53:20 +00:00
treeOutput.imbue(std::locale(output.getloc(), codeCvtToUTF8));
2021-04-30 12:55:56 +00:00
}
~SyntaxParser() {
2021-05-12 11:53:20 +00:00
input.close();
2021-04-30 12:55:56 +00:00
output.close();
2021-05-12 11:53:20 +00:00
treeOutput.close();
2021-04-30 12:55:56 +00:00
}
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD>ʽ
void getToken();
void printSymbol(int symbol_index);
void printProduction(const Production *p_pdt);
// <20>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB7A8><EFBFBD><EFBFBD>
void parse();
2021-05-12 11:53:20 +00:00
void printError(std::wofstream &errOutput);
2021-04-30 12:55:56 +00:00
void printError();
void printDone();
2021-05-12 11:53:20 +00:00
2021-04-30 12:55:56 +00:00
};
#endif //SYNTAXPARSER_SYNTAXPARSER_H