Modules/Language/public/Parser.hpp
Шурупов Илья Викторович 5fce4b2074 Language: reorganize code
2026-10-08 18:09:18 +03:00

55 lines
1.7 KiB
C++

#pragma once
#include "compilers/RegularCompiler.hpp"
#include "automatas/DetFinateStateAutomata.hpp"
#include "compilers/ContextFreeCompiler.hpp"
#include "automatas/DetPushDownAutomata.hpp"
namespace tp {
template <typename tAlphabetType, typename tTokenType, tTokenType tInTransition, ualni MinSymbol, ualni MaxSymbol>
class Parser {
using ParserRegularGrammar = RegularGrammar<tAlphabetType, tTokenType>;
using ParserRegularCompiler = RegularCompiler<tAlphabetType, tTokenType, tInTransition, MinSymbol, MaxSymbol>;
using RegularGraph = FiniteStateAutomation<tAlphabetType, tTokenType>;
using ParserRegularAutomata = DetFinateStateAutomata<tAlphabetType, tTokenType>;
using ContextFreeGraph = FiniteStateAutomation<ContextFreeCompiler::SymbolVal, ContextFreeCompiler::Item>;
using ParserContextFreeAutomata = DetPushDownAutomata<ContextFreeCompiler::SymbolVal, ContextFreeCompiler::Item>;
public:
struct ParseResult {
bool accepted = false;
const ParserContextFreeAutomata::StackItem* ast = nullptr;
};
public:
Parser() = default;
void setIgnoreToken(tTokenType token);
public:
bool compileTables(
const ContextFreeGrammar& cfGrammar,
const ParserRegularGrammar& reGrammar,
const Map<String, tTokenType>& contextFreeToRegular
);
ParseResult parse(const tAlphabetType* sentence, ualni sentenceLength);
public:
// save load compiled tables
ParserRegularAutomata mRegularAutomata;
ParserContextFreeAutomata mContextFreeAutomata;
Map<tTokenType, ContextFreeCompiler::SymbolVal> mGrammarGlue;
Map<ContextFreeCompiler::SymbolVal, String> mAstNames;
tTokenType mIgnoreToken = tTokenType();
};
}
#include "Parser.ipp"