From 5972f0ef4c57e324091b1e8307e438b15ff1465d Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Thu, 4 Mar 2021 11:16:59 +0100 Subject: [PATCH] Add a (definetly incomplete) ParseComponents.hpp file and move the extern declarations of main.cpp to misc.hpp. --- CMakeLists.txt | 2 +- src/headers/ParseComponents.hpp | 27 +++++++++++++++++++++++++++ src/headers/misc.hpp | 7 +++++++ src/main.cpp | 9 ++------- src/parser/MainParse.cpp | 10 +++++----- src/transpiler/MainTranspile.cpp | 6 ++++-- 6 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/headers/ParseComponents.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 58c20fd..c7b3919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TI set(CPACK_STRIP_FILES TRUE) include_directories(${CMAKE_CURRENT_LIST_DIR}) -add_executable(ybcon src/main.cpp resources/Yerbacon.rc src/parser/MainParse.cpp src/transpiler/MainTranspile.cpp src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp) +add_executable(ybcon src/main.cpp resources/Yerbacon.rc src/parser/MainParse.cpp src/transpiler/MainTranspile.cpp src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/ParseComponents.hpp) target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${PROJECT_VERSION}") # lpkg = linux package, wpkg = windows package diff --git a/src/headers/ParseComponents.hpp b/src/headers/ParseComponents.hpp new file mode 100644 index 0000000..e83eab1 --- /dev/null +++ b/src/headers/ParseComponents.hpp @@ -0,0 +1,27 @@ +// +// Created by doggo on 03/03/2021. +// + +#ifndef YERBACON_PARSECOMPONENTS_HPP +#define YERBACON_PARSECOMPONENTS_HPP + +#include +#include +using namespace std; + +class ParseComponent { +public: + +}; + +class ParseTree { +protected: + vector subComponents; +public: + auto getComponents() { return subComponents; } + void add(const ParseComponent component) { subComponents.emplace_back(component); }; + void addAll(const vector& components) { for (const auto& comp: components) add(comp); } + ParseTree(): subComponents() {}; +}; + +#endif //YERBACON_PARSECOMPONENTS_HPP diff --git a/src/headers/misc.hpp b/src/headers/misc.hpp index 411d33d..4c145af 100644 --- a/src/headers/misc.hpp +++ b/src/headers/misc.hpp @@ -12,4 +12,11 @@ #include std::string getVersion() noexcept { return YBCON_VERSION; } +string getFileContent(const string& file); +void setOutputFileContent(const string& language, const string& file, const string& content); + +#include "ParseComponents.hpp" +ParseTree parseString(unique_ptr toParse); +string transpile(ParseTree toTranspile, string language); + #endif //YERBACON_MISC_HPP diff --git a/src/main.cpp b/src/main.cpp index 7b83d36..b323001 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,11 +2,6 @@ #include using namespace std; -extern string getFileContent(const string& file); -extern void setOutputFileContent(const string& language, const string& file, const string& content); -extern string parseString(unique_ptr toParse); -extern string transpile(string toTranspile, string language); - #include "headers/misc.hpp" int main(int argc, char* argv[]) { @@ -23,8 +18,8 @@ int main(int argc, char* argv[]) { if ((currentArg == "--printresult") || (currentArg == "-p")) printResult = true; else if (currentArg.starts_with("--target=")) target = '.' + currentArg.erase(0, 9); } - const string parsedString = parseString(make_unique(getFileContent(fileName))); - const string transpiledString = transpile(parsedString, target); + const auto parsedTree = parseString(make_unique(getFileContent(fileName))); + const string transpiledString = transpile(parsedTree, target); if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; setOutputFileContent(target, fileName.erase(fileName.find(".ybcon")) + target, transpiledString); } diff --git a/src/parser/MainParse.cpp b/src/parser/MainParse.cpp index d81b201..cc10d0a 100644 --- a/src/parser/MainParse.cpp +++ b/src/parser/MainParse.cpp @@ -2,16 +2,16 @@ // Created by username404 on 11/12/2020. // #include "../headers/lex.hpp" +#include "../headers/ParseComponents.hpp" using namespace std; -string parseString(unique_ptr toParse) { - stringstream tmpStream; +ParseTree parseString(unique_ptr toParse) { + ParseTree parseTree = ParseTree(); auto lexed = lex(*toParse); for (tok& token: lexed) { - tmpStream << token; + } - *toParse = tmpStream.str(); - return *toParse; + return parseTree; // TODO Actually parse } \ No newline at end of file diff --git a/src/transpiler/MainTranspile.cpp b/src/transpiler/MainTranspile.cpp index 9ac11ae..1916056 100644 --- a/src/transpiler/MainTranspile.cpp +++ b/src/transpiler/MainTranspile.cpp @@ -20,9 +20,11 @@ pair validLanguage(const string& it) { } return pair(selected, valid); } +#include "../headers/ParseComponents.hpp" -string transpile(string toTranspile, string language) +string transpile(ParseTree tree, string language) { + string transpiled; auto valided = validLanguage(language); if (valided.second) { switch (valided.first) { @@ -39,5 +41,5 @@ string transpile(string toTranspile, string language) cout << '"' << (char) toupper(language.at(1)) << language.erase(0, 2) << "\" is not a valid target."; exit(1); } - return toTranspile; + return transpiled; } \ No newline at end of file