Language Initial
This commit is contained in:
parent
14cb588948
commit
fae4d83f97
47 changed files with 831 additions and 14 deletions
43
Language/tests/Test.hpp
Normal file
43
Language/tests/Test.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include "SimpleParser.hpp"
|
||||
|
||||
const char* gGrammar = R"(
|
||||
# Grammar in the CF-RE United Format (Defined by language module)
|
||||
|
||||
Rules : {
|
||||
ScopeList : ScopeList Scope | Scope ;
|
||||
Scope : \ScopeBegin StatementList \ScopeEnd;
|
||||
StatementList : StatementList Statement \StatementEnd;
|
||||
StatementList : Statement \StatementEnd;
|
||||
Statement : \StatementBody;
|
||||
}
|
||||
|
||||
Terminals : {
|
||||
Space : " " | "\t" | "\n" | "\r";
|
||||
ScopeBegin : "{";
|
||||
ScopeEnd : "}";
|
||||
StatementEnd : ";";
|
||||
StatementBody : "a" | "b";
|
||||
}
|
||||
|
||||
Start : Scope;
|
||||
Ignore : Space;
|
||||
)";
|
||||
|
||||
const char* gSentence = R"(
|
||||
{}
|
||||
|
||||
{ }
|
||||
|
||||
{
|
||||
a;
|
||||
a ; a ;
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
a;
|
||||
a;
|
||||
}
|
||||
)";
|
||||
29
Language/tests/Tests.cpp
Normal file
29
Language/tests/Tests.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
#include "Test.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
void test() {
|
||||
auto parser = SimpleParser();
|
||||
auto grammar = Sentence(gGrammar);
|
||||
|
||||
auto sentence = Sentence(gSentence);
|
||||
auto ast = AST();
|
||||
|
||||
parser.compileTables(grammar);
|
||||
parser.parse(sentence, ast);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
tp::ModuleManifest* deps[] = { &tp::gModuleLanguage, nullptr };
|
||||
tp::ModuleManifest testModule("Test", nullptr, nullptr, deps);
|
||||
|
||||
if (!testModule.initialize()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
testModule.deinitialize();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue