diff --git a/Language/private/AST.cpp b/Language/private/AST.cpp deleted file mode 100644 index 755eb75..0000000 --- a/Language/private/AST.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "AST.hpp" - -using namespace tp; diff --git a/Language/private/GrammarCompiler.cpp b/Language/private/GrammarCompiler.cpp deleted file mode 100644 index 6501d1d..0000000 --- a/Language/private/GrammarCompiler.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "GrammarCompiler.hpp" - -using namespace tp; \ No newline at end of file diff --git a/Language/private/Parser.cpp b/Language/private/Parser.cpp deleted file mode 100644 index 113f363..0000000 --- a/Language/private/Parser.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -#include "Parser.hpp" - -using namespace tp; - -void Parser::compileTables(const ContextFreeGrammar& cfGrammar, const RegularGrammar& reGrammar) {} - -void Parser::parse(const Sentence& sentence, AST& out) {} \ No newline at end of file diff --git a/Language/private/Sentence.cpp b/Language/private/Sentence.cpp deleted file mode 100644 index 92a4b7b..0000000 --- a/Language/private/Sentence.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "Sentence.hpp" - -using namespace tp; \ No newline at end of file diff --git a/Language/private/SimpleParser.cpp b/Language/private/SimpleParser.cpp deleted file mode 100644 index 81f6ae9..0000000 --- a/Language/private/SimpleParser.cpp +++ /dev/null @@ -1,47 +0,0 @@ - -#include "NewPlacement.hpp" - -#include "SimpleParser.hpp" - -using namespace tp; - -SimpleParser::SimpleParser() { - // Grammar for unified grammar format sentence that tables compiled from - - // Define Context-Free grammar - ContextFreeGrammar contextFreeGrammar; - { - // use existing CF grammar interface - contextFreeGrammar.addRule("a", { ContextFreeGrammar::Arg("") }); - contextFreeGrammar.setStart("a"); - } - - // Define Regular grammar - RegularGrammar rg; - { - // this is basically ast from existing tokenizer - rg.addRule(rg.seq({ rg.val('a'), rg.val('b') }), 0); - } - - mUnifiedGrammarParser.compileTables(contextFreeGrammar, rg); -} - -void SimpleParser::compileTables(const Sentence& grammar) { - AST unifiedGrammarAst; - mUnifiedGrammarParser.parse(grammar, unifiedGrammarAst); - - // compile each ast into RegularGrammar and ContextFree Grammar api instructions - ContextFreeGrammar userContextFreeGrammar; - RegularGrammar userRegularGrammar; - - // ... - // split ast into RE and CF part - // generate and execute grammar api commands - // use existing tokenizer code to create RE transition matrix - // ... - // compile tables from user grammar - - mUserParser.compileTables(userContextFreeGrammar, userRegularGrammar); -} - -void SimpleParser::parse(const Sentence& sentence, AST& out) { mUserParser.parse(sentence, out); } \ No newline at end of file diff --git a/Language/public/Parser.hpp b/Language/public/Parser.hpp index 17ed6df..519ee4a 100644 --- a/Language/public/Parser.hpp +++ b/Language/public/Parser.hpp @@ -3,16 +3,17 @@ #include "AST.hpp" #include "GrammarCompiler.hpp" -#include "Sentence.hpp" namespace tp { + + template class Parser { public: Parser() = default; public: - void compileTables(const ContextFreeGrammar& cfGrammar, const RegularGrammar& reGrammar); - void parse(const Sentence& sentence, AST& out); + void compileTables(const ContextFreeGrammar& cfGrammar, const RegularGrammar& reGrammar) {} + void parse(const tAlphabetType* sentence, ualni sentenceLength, AST& out) {} public: // save load compiled tables diff --git a/Language/public/Sentence.hpp b/Language/public/Sentence.hpp deleted file mode 100644 index 82bdf2b..0000000 --- a/Language/public/Sentence.hpp +++ /dev/null @@ -1,13 +0,0 @@ - -#pragma once - -#include "LanguageCommon.hpp" - -namespace tp { - struct Sentence { - const int1* buffer = nullptr; - alni symbolSize = 1; - - explicit Sentence(const char* buff) { buffer = buff; } - }; -} diff --git a/Language/public/SimpleParser.hpp b/Language/public/SimpleParser.hpp index 39c7b26..940ca32 100644 --- a/Language/public/SimpleParser.hpp +++ b/Language/public/SimpleParser.hpp @@ -5,16 +5,53 @@ namespace tp { // Gives ability to express grammar in the Unified Format as sentence + template class SimpleParser { public: - SimpleParser(); + SimpleParser() { + // Grammar for unified grammar format sentence that tables compiled from + + // Define Context-Free grammar + ContextFreeGrammar contextFreeGrammar; + { + // use existing CF grammar interface + contextFreeGrammar.addRule("a", { ContextFreeGrammar::Arg("") }); + contextFreeGrammar.setStart("a"); + } + + // Define Regular grammar + RegularGrammar rg; + { + // this is basically ast from existing tokenizer + rg.addRule(rg.seq({ rg.val('a'), rg.val('b') }), 0); + } + + mUnifiedGrammarParser.compileTables(contextFreeGrammar, rg); + } public: - void compileTables(const Sentence& grammar); - void parse(const Sentence& sentence, AST& out); + void compileTables(const tAlphabetType* grammar, ualni grammarLength) { + AST unifiedGrammarAst; + mUnifiedGrammarParser.parse(grammar, grammarLength, unifiedGrammarAst); + + // compile each ast into RegularGrammar and ContextFree Grammar api instructions + ContextFreeGrammar userContextFreeGrammar; + RegularGrammar userRegularGrammar; + + // ... + // split ast into RE and CF part + // generate and execute grammar api commands + // use existing tokenizer code to create RE transition matrix + // ... + // compile tables from user grammar + + mUserParser.compileTables(userContextFreeGrammar, userRegularGrammar); + } + + void parse(const tAlphabetType* grammar, ualni grammarLength, AST& out) { mUserParser.parse(grammar, grammarLength, out); } private: - Parser mUnifiedGrammarParser; - Parser mUserParser; + Parser mUnifiedGrammarParser; + Parser mUserParser; }; } diff --git a/Language/tests/Tests.cpp b/Language/tests/Tests.cpp index 718f1cd..cbcb6b3 100644 --- a/Language/tests/Tests.cpp +++ b/Language/tests/Tests.cpp @@ -1,17 +1,15 @@ +#include "NewPlacement.hpp" #include "Test.hpp" using namespace tp; void test() { - auto parser = SimpleParser(); - auto grammar = Sentence(gGrammar); - - auto sentence = Sentence(gSentence); + auto parser = SimpleParser(); auto ast = AST(); - parser.compileTables(grammar); - parser.parse(sentence, ast); + parser.compileTables(gGrammar, String::Logic::calcLength(gGrammar)); + parser.parse(gSentence, String::Logic::calcLength(gSentence), ast); } int main() {