Language Initial
This commit is contained in:
parent
14cb588948
commit
fae4d83f97
47 changed files with 831 additions and 14 deletions
4
Language/private/AST.cpp
Normal file
4
Language/private/AST.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
#include "AST.hpp"
|
||||
|
||||
using namespace tp;
|
||||
4
Language/private/Grammar.cpp
Normal file
4
Language/private/Grammar.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
#include "Grammar.hpp"
|
||||
|
||||
using namespace tp;
|
||||
4
Language/private/GrammarCompiler.cpp
Normal file
4
Language/private/GrammarCompiler.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
#include "GrammarCompiler.hpp"
|
||||
|
||||
using namespace tp;
|
||||
8
Language/private/LanguageCommon.cpp
Normal file
8
Language/private/LanguageCommon.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "LanguageCommon.hpp"
|
||||
#include "Strings.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
static ModuleManifest* sModuleDependencies[] = { &gModuleStrings, nullptr };
|
||||
ModuleManifest tp::gModuleLanguage = ModuleManifest("Language", nullptr, nullptr, sModuleDependencies);
|
||||
8
Language/private/Parser.cpp
Normal file
8
Language/private/Parser.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include "Parser.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
void Parser::compileTables(const ContextFreeGrammar& cfGrammar, const RegularGrammar& reGrammar) {}
|
||||
|
||||
void Parser::parse(const Sentence& sentence, AST& out) {}
|
||||
4
Language/private/Sentence.cpp
Normal file
4
Language/private/Sentence.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
#include "Sentence.hpp"
|
||||
|
||||
using namespace tp;
|
||||
49
Language/private/SimpleParser.cpp
Normal file
49
Language/private/SimpleParser.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
#include "SimpleParser.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
SimpleParser::SimpleParser() {
|
||||
// Grammar for unified grammar format sentence that tables compiled from
|
||||
|
||||
// Define Context-Free grammar
|
||||
ContextFreeGrammar contextFreeGrammar;
|
||||
{
|
||||
auto term = contextFreeGrammar.createTerminal();
|
||||
|
||||
auto nonTerm = contextFreeGrammar.createNonTerminal();
|
||||
auto nonTerm2 = contextFreeGrammar.createNonTerminal();
|
||||
|
||||
contextFreeGrammar.addRule(nonTerm, { term, nonTerm2 });
|
||||
contextFreeGrammar.addRule();
|
||||
|
||||
contextFreeGrammar.setStart(nonTerm);
|
||||
}
|
||||
|
||||
// Define Regular grammar
|
||||
RegularGrammar regularGrammar;
|
||||
{
|
||||
regularGrammar.addRule(regularGrammar.alternate(regularGrammar.repeat(regularGrammar.symbols("asd")), regularGrammar.symbol("a")));
|
||||
regularGrammar.addRule(regularGrammar.alternate(regularGrammar.repeat(regularGrammar.symbols("asd")), regularGrammar.symbol("a")));
|
||||
}
|
||||
|
||||
mUnifiedGrammarParser.compileTables(contextFreeGrammar, regularGrammar);
|
||||
}
|
||||
|
||||
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
|
||||
// ...
|
||||
|
||||
// compile tables from user grammar
|
||||
mUserParser.compileTables(userContextFreeGrammar, userRegularGrammar);
|
||||
}
|
||||
|
||||
void SimpleParser::parse(const Sentence& sentence, AST& out) { mUserParser.parse(sentence, out); }
|
||||
Loading…
Add table
Add a link
Reference in a new issue