Make parser template class
This commit is contained in:
parent
38957e678b
commit
656da1fd76
9 changed files with 50 additions and 94 deletions
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
#include "AST.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
#include "GrammarCompiler.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
|
@ -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) {}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
#include "Sentence.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
|
@ -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<uint1, int1> 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<uint1, int1> 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); }
|
||||
Loading…
Add table
Add a link
Reference in a new issue