diff --git a/CMakeLists.txt b/CMakeLists.txt index 533cb99..83c166d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "Yerbacon ${CMAKE_PROJECT_VERSION_MAJOR}.${C set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TIME}") include_directories(${CMAKE_CURRENT_LIST_DIR}) -add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.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/parsing/ParseComponents.hpp src/headers/transpiler/Target.hpp src/headers/transpiler/implementations/Lua.hpp src/headers/transpiler/implementations/Js.hpp src/headers/transpiler/implementations/Py.hpp) +add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.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/parsing/ParseComponents.hpp src/headers/transpiler/Target.hpp src/headers/transpiler/implementations/Lua.hpp src/headers/transpiler/implementations/Js.hpp src/headers/transpiler/implementations/Py.hpp src/headers/parsing/Parser.hpp) target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}") # lpkg = linux package, wpkg = windows package diff --git a/src/headers/lex.hpp b/src/headers/lex.hpp index cae5aea..7031e54 100644 --- a/src/headers/lex.hpp +++ b/src/headers/lex.hpp @@ -3,6 +3,7 @@ #include #include +#include #include struct tok { @@ -13,9 +14,9 @@ struct tok { IDENTIFIER, UNEXPECTED }; - type toktype; - std::string toktext; - tok(type Type, std::string Text): toktype(Type), toktext(Text) {} + const type toktype; + const std::string toktext; + tok(type Type, std::string_view Text): toktype(Type), toktext(Text) {} friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; } }; std::vector lex(const std::string& in); diff --git a/src/headers/misc.hpp b/src/headers/misc.hpp index d1ff6d7..277ed42 100644 --- a/src/headers/misc.hpp +++ b/src/headers/misc.hpp @@ -12,6 +12,8 @@ void outputFileContent(const string& file, string_view content); #include "src/headers/parsing/ParseComponents.hpp" ParseTree parseString(const string& toParse); -string transpile(ParseTree toTranspile, string language); + +#include +string transpile(const ParseTree& tree, const string_view& language); #endif //YERBACON_MISC_HPP diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index 7cee510..2d7580f 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -2,6 +2,7 @@ #define YERBACON_PARSECOMPONENTS_HPP #include +#include #include using namespace std; @@ -9,7 +10,7 @@ using namespace std; class ParseComponent {}; -struct ParseTree: public ParseComponent { +class ParseTree: public ParseComponent { private: mutable unsigned int compCount = 0; protected: @@ -30,7 +31,7 @@ public: }; namespace StandardComponents::types { - + struct [[deprecated]] Expression: ParseComponent {}; } #endif //YERBACON_PARSECOMPONENTS_HPP diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp new file mode 100644 index 0000000..a4750ec --- /dev/null +++ b/src/headers/parsing/Parser.hpp @@ -0,0 +1,21 @@ +#ifndef YERBACON_PARSER_HPP +#define YERBACON_PARSER_HPP + +#include + +namespace Parser { + ParseTree parseVector(const vector& lexed) { + ParseTree parseTree = ParseTree(); + using namespace StandardComponents::types; + for (unsigned int i = 1; i < lexed.size(); ++i) { + const auto& previous = lexed[i - 1]; + const auto& current = lexed[i]; + const auto& next = lexed[i + 1]; + + + } + return parseTree; + } +} + +#endif //YERBACON_PARSER_HPP diff --git a/src/parser/MainParse.cpp b/src/parser/MainParse.cpp index 01da860..fe394cc 100644 --- a/src/parser/MainParse.cpp +++ b/src/parser/MainParse.cpp @@ -1,14 +1,9 @@ #include "../headers/lex.hpp" #include "../headers/parsing/ParseComponents.hpp" +#include "../headers/parsing/Parser.hpp" using namespace std; ParseTree parseString(const string& toParse) { - ParseTree parseTree = ParseTree(); - auto lexed = lex(toParse); - for (const tok& token: lexed) { - - } - return parseTree; - // TODO Actually parse + return Parser::parseVector(lex(toParse)); } \ No newline at end of file diff --git a/src/transpiler/MainTranspile.cpp b/src/transpiler/MainTranspile.cpp index c641d2c..9302938 100644 --- a/src/transpiler/MainTranspile.cpp +++ b/src/transpiler/MainTranspile.cpp @@ -1,5 +1,4 @@ -#include - +#include using namespace std; enum LANGUAGE: unsigned short { NONE, LUA, JS, PY }; @@ -7,6 +6,6 @@ const string_view languages[3] = { ".lua", ".js", ".py"}; #include "../headers/transpiler/Target.hpp" -string transpile(const ParseTree tree, string language) { +string transpile(const ParseTree& tree, const string_view& language) { return Target::forName(language)->transpileWithTree(tree); } \ No newline at end of file