Apply formating to all files. CLeanup
This commit is contained in:
parent
b4ae5dde77
commit
91fb72bd49
928 changed files with 14515 additions and 21479 deletions
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#include "Parser.hpp"
|
||||
#include "CommandLine.hpp"
|
||||
#include "Parser.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
|
|
@ -29,7 +29,8 @@ void run(const String& source) {
|
|||
grammar.generateSentences(sentences);
|
||||
|
||||
printf("Example sentences formed from grammar: \n");
|
||||
for (auto sentence : sentences) tp::CfGrammar::printSentence(sentence.data());
|
||||
for (auto sentence : sentences)
|
||||
tp::CfGrammar::printSentence(sentence.data());
|
||||
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
}
|
||||
|
|
@ -50,7 +51,7 @@ int main(int argc, const char* argv[]) {
|
|||
printf("\n");
|
||||
|
||||
CommandLine cmd = {
|
||||
{ "grammar", CommandLine::Arg::STR },
|
||||
{ "grammar", CommandLine::Arg::STR },
|
||||
};
|
||||
|
||||
if (!cmd.parse((char) argc, argv, true, 1)) {
|
||||
|
|
@ -73,7 +74,6 @@ int main(int argc, const char* argv[]) {
|
|||
grammar.resize((String::Index) size);
|
||||
file.readBytes(grammar.write(), size);
|
||||
|
||||
|
||||
run(grammar);
|
||||
|
||||
file.disconnect();
|
||||
|
|
|
|||
|
|
@ -13,14 +13,8 @@ void CLR::setGrammar(const tp::CfGrammar& grammar) {
|
|||
mState = ParserState::FAILED;
|
||||
}
|
||||
|
||||
void CLR::setTerminal(const String& name, TerminalStream::TerminalID id) {
|
||||
void CLR::setTerminal(const String& name, TerminalStream::TerminalID id) {}
|
||||
|
||||
}
|
||||
void CLR::build() {}
|
||||
|
||||
void CLR::build() {
|
||||
|
||||
}
|
||||
|
||||
void CLR::parse(TerminalStream* source, List<ASTNode>& out, ASTNode** root) {
|
||||
*root = nullptr;
|
||||
}
|
||||
void CLR::parse(TerminalStream* source, List<ASTNode>& out, ASTNode** root) { *root = nullptr; }
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
#include "CfGrammar.hpp"
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#include "Timing.hpp"
|
||||
|
||||
|
|
@ -16,10 +16,10 @@ void CfGrammar::generateSentences(List<Sentence>& out) {
|
|||
|
||||
// add start production
|
||||
Sentence start;
|
||||
start.terms.pushBack( { startTerminal, false } );
|
||||
start.terms.pushBack({ startTerminal, false });
|
||||
queue.pushBack(start);
|
||||
|
||||
PASS:
|
||||
PASS:
|
||||
|
||||
auto const sentential = &queue.first()->data;
|
||||
bool isSentence = true;
|
||||
|
|
|
|||
|
|
@ -43,16 +43,16 @@ typedef Buffer<State> Automata;
|
|||
|
||||
void initializeTokenizer(CFGTokenizer* tok) {
|
||||
tok->build({
|
||||
{ CFGTokenizer::tTokenizer::etherRE, Token::IGNORED },
|
||||
{ "Start", Token::START },
|
||||
{ ":", Token::EQUAL },
|
||||
{ "\\[", Token::TERMINAL_START },
|
||||
{ "\\]", Token::TERMINAL_END },
|
||||
{ "\\|", Token::ALTERNATION },
|
||||
{ ";", Token::RULE_END },
|
||||
{ "&", Token::EPSILON },
|
||||
{ CFGTokenizer::tTokenizer::idRE, Token::ID },
|
||||
{ CFGTokenizer::tTokenizer::commentBlockRE, Token::COMMENT },
|
||||
{ CFGTokenizer::tTokenizer::etherRE, Token::IGNORED },
|
||||
{ "Start", Token::START },
|
||||
{ ":", Token::EQUAL },
|
||||
{ "\\[", Token::TERMINAL_START },
|
||||
{ "\\]", Token::TERMINAL_END },
|
||||
{ "\\|", Token::ALTERNATION },
|
||||
{ ";", Token::RULE_END },
|
||||
{ "&", Token::EPSILON },
|
||||
{ CFGTokenizer::tTokenizer::idRE, Token::ID },
|
||||
{ CFGTokenizer::tTokenizer::commentBlockRE, Token::COMMENT },
|
||||
});
|
||||
|
||||
ASSERT(tok->isBuild())
|
||||
|
|
@ -71,54 +71,54 @@ void initAutomata(Automata& automata) {
|
|||
auto terminalEnd = states;
|
||||
|
||||
root->transitions = {
|
||||
{ Token::END, end },
|
||||
{ Token::START, start },
|
||||
{ Token::ID, rule, [](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.pushBack({ tok, {} });
|
||||
}
|
||||
},
|
||||
{ Token::END, end },
|
||||
{ Token::START, start },
|
||||
{ Token::ID,
|
||||
rule,
|
||||
[](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.pushBack({ tok, {} });
|
||||
} },
|
||||
};
|
||||
|
||||
start->transitions = {
|
||||
{ Token::ID,
|
||||
root,
|
||||
[](CfGrammar* grammar, const String& tok) {
|
||||
grammar->startTerminal = tok;
|
||||
}
|
||||
},
|
||||
{ Token::ID, root, [](CfGrammar* grammar, const String& tok) { grammar->startTerminal = tok; } },
|
||||
};
|
||||
|
||||
rule->transitions = {
|
||||
{ Token::EQUAL, rhs },
|
||||
{ Token::EQUAL, rhs },
|
||||
};
|
||||
|
||||
rhs->transitions = {
|
||||
{ Token::ALTERNATION, rhs, [](CfGrammar* grammar, const String& tok) {
|
||||
auto const& id = grammar->rules.last()->data.id;
|
||||
grammar->rules.pushBack({ id, {} });
|
||||
}
|
||||
},
|
||||
{ Token::ID, rhs, [](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.last()->data.args.pushBack({ tok, false, false });
|
||||
}
|
||||
},
|
||||
{ Token::EPSILON, rhs, [](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.last()->data.args.pushBack({ tok, false, true });
|
||||
}
|
||||
},
|
||||
{ Token::TERMINAL_START, terminalStart },
|
||||
{ Token::RULE_END, root },
|
||||
{ Token::ALTERNATION,
|
||||
rhs,
|
||||
[](CfGrammar* grammar, const String& tok) {
|
||||
auto const& id = grammar->rules.last()->data.id;
|
||||
grammar->rules.pushBack({ id, {} });
|
||||
} },
|
||||
{ Token::ID,
|
||||
rhs,
|
||||
[](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.last()->data.args.pushBack({ tok, false, false });
|
||||
} },
|
||||
{ Token::EPSILON,
|
||||
rhs,
|
||||
[](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.last()->data.args.pushBack({ tok, false, true });
|
||||
} },
|
||||
{ Token::TERMINAL_START, terminalStart },
|
||||
{ Token::RULE_END, root },
|
||||
};
|
||||
|
||||
terminalStart->transitions = {
|
||||
{ Token::ID, terminalEnd, [](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.last()->data.args.pushBack({ tok, true, false });
|
||||
}
|
||||
},
|
||||
{ Token::ID,
|
||||
terminalEnd,
|
||||
[](CfGrammar* grammar, const String& tok) {
|
||||
grammar->rules.last()->data.args.pushBack({ tok, true, false });
|
||||
} },
|
||||
};
|
||||
|
||||
terminalEnd->transitions = {
|
||||
{ Token::TERMINAL_END, rhs },
|
||||
{ Token::TERMINAL_END, rhs },
|
||||
};
|
||||
|
||||
auto idError = "Expected an identifier";
|
||||
|
|
@ -196,14 +196,8 @@ CfGrammarParserState* CfGrammar::initializeCfGrammarParser() {
|
|||
return state;
|
||||
}
|
||||
|
||||
void CfGrammar::deinitializeCfGrammarParser(CfGrammarParserState* state) {
|
||||
delete state;
|
||||
}
|
||||
void CfGrammar::deinitializeCfGrammarParser(CfGrammarParserState* state) { delete state; }
|
||||
|
||||
bool CfGrammar::parse(CfGrammarParserState* context, const String& source) {
|
||||
return ::parse(source.read(), &context->automata, &context->tokenizer, this);
|
||||
}
|
||||
bool CfGrammar::parse(CfGrammarParserState* context, const String& source) { return ::parse(source.read(), &context->automata, &context->tokenizer, this); }
|
||||
|
||||
bool CfGrammar::isLooped() const {
|
||||
return mIsLooped;
|
||||
}
|
||||
bool CfGrammar::isLooped() const { return mIsLooped; }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "NewPlacement.hpp"
|
||||
#include "Parser.hpp"
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#include "Tokenizer.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,13 @@ namespace tp {
|
|||
|
||||
class Automation {
|
||||
public:
|
||||
class State {
|
||||
|
||||
};
|
||||
class State {};
|
||||
};
|
||||
|
||||
class TerminalStream {
|
||||
public:
|
||||
typedef ualni TerminalID;
|
||||
|
||||
public:
|
||||
TerminalStream() = default;
|
||||
virtual TerminalID getNextTerminal() = 0;
|
||||
|
|
@ -36,9 +35,7 @@ namespace tp {
|
|||
};
|
||||
|
||||
private:
|
||||
class SententialStack {
|
||||
|
||||
};
|
||||
class SententialStack {};
|
||||
|
||||
public:
|
||||
CLR() = default;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "Strings.hpp"
|
||||
#include "List.hpp"
|
||||
#include "Map.hpp"
|
||||
#include "Strings.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
|
|
@ -13,17 +13,13 @@ namespace tp {
|
|||
bool isTerminal = false;
|
||||
bool isEpsilon = false;
|
||||
|
||||
bool operator==(const Arg& in) const {
|
||||
return (id == in.id) && (isEpsilon == in.isEpsilon) && (isTerminal == in.isTerminal);
|
||||
}
|
||||
bool operator==(const Arg& in) const { return (id == in.id) && (isEpsilon == in.isEpsilon) && (isTerminal == in.isTerminal); }
|
||||
};
|
||||
|
||||
String id;
|
||||
List<Arg> args;
|
||||
|
||||
bool operator==(const Rule& in) const {
|
||||
return (id == in.id) && (args == in.args);
|
||||
}
|
||||
bool operator==(const Rule& in) const { return (id == in.id) && (args == in.args); }
|
||||
|
||||
[[nodiscard]] bool isProductive() const {
|
||||
for (auto arg : args) {
|
||||
|
|
@ -37,9 +33,7 @@ namespace tp {
|
|||
struct Term {
|
||||
String id;
|
||||
bool terminal;
|
||||
bool operator==(const Term& in) const {
|
||||
return (id == in.id) && (terminal == in.terminal);
|
||||
}
|
||||
bool operator==(const Term& in) const { return (id == in.id) && (terminal == in.terminal); }
|
||||
};
|
||||
List<Term> terms;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
#include "Testing.hpp"
|
||||
#include "Parser.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
TEST_DEF(CLR) {
|
||||
//TEST(false);
|
||||
// TEST(false);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
#include "Testing.hpp"
|
||||
#include "Parser.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
|
|
@ -40,9 +40,10 @@ List : [ LIST ];
|
|||
TEST_ASSERT(sentences.first()->data.terms.length() == 1);
|
||||
TEST_ASSERT(sentences.last()->data.terms.length() == 1);
|
||||
|
||||
TEST(sentences.first()->data.terms.first()->data.id == "Function");
|
||||
TEST(sentences.first()->data.terms.first()->data.id == "Function");
|
||||
TEST(sentences.last()->data.terms.first()->data.id == "LIST");
|
||||
|
||||
printf("Example sentences formed from grammar: \n");
|
||||
for (auto sentence : sentences) tp::CfGrammar::printSentence(sentence.data());
|
||||
for (auto sentence : sentences)
|
||||
tp::CfGrammar::printSentence(sentence.data());
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
#include "Testing.hpp"
|
||||
#include "Parser.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue