- Fix determinization (NFA->DFA subset construction) in Automata - Implement RegularAutomata longest-match tokenizer - Implement ContextFreeCompiler: canonical LR(1) tables with %left/%right precedence - Implement ContextFreeAutomata shift/reduce DPDA with AST build - Split regex (RG+CFG) and epsilon transitions in RegularCompiler - Add UnifiedGrammarFormat (header + source): defines the .g grammar syntax and the inline regex syntax via the C++ grammar API, and translates a parsed .g AST into target RE + CFG grammars (bootstrap) - SimpleParser: bootstrap .g grammar files -> RE + LALR tables -> parse input - Fix Map iterator off-by-one (last bucket never visited) - Tests: compile a .g grammar and parse a program to a valid AST
46 lines
877 B
C++
46 lines
877 B
C++
|
|
#include "Test.hpp"
|
|
|
|
using namespace tp;
|
|
|
|
void testAutomation() {
|
|
|
|
FiniteStateAutomation<char, int> automata;
|
|
|
|
auto start = automata.addState(0, false);
|
|
auto end = automata.addState(1, true);
|
|
|
|
automata.addTransition(start, end, 'a');
|
|
|
|
automata.setStartState(start);
|
|
|
|
automata.makeDeterministic();
|
|
}
|
|
|
|
void test() {
|
|
auto parser = SimpleParser<int1>();
|
|
|
|
parser.compileTables(gGrammar, String::Logic::calcLength(gGrammar));
|
|
DEBUG_ASSERT(parser.isCompiled());
|
|
|
|
auto result = parser.parse(gSentence, String::Logic::calcLength(gSentence));
|
|
DEBUG_ASSERT(result.accepted);
|
|
DEBUG_ASSERT(result.ast);
|
|
}
|
|
|
|
int main() {
|
|
|
|
tp::ModuleManifest* deps[] = { &tp::gModuleStrings, nullptr };
|
|
tp::ModuleManifest testModule("LanguageTest", nullptr, nullptr, deps);
|
|
|
|
if (!testModule.initialize()) {
|
|
return 1;
|
|
}
|
|
|
|
testAutomation();
|
|
test();
|
|
|
|
testModule.deinitialize();
|
|
|
|
return 0;
|
|
}
|