Begin the parser

This commit is contained in:
Username404 2021-07-03 21:54:12 +02:00
parent 995684799d
commit 077f95b36b
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
7 changed files with 36 additions and 17 deletions

View File

@ -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

View File

@ -3,6 +3,7 @@
#include <vector>
#include <string>
#include <string_view>
#include <ostream>
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<tok> lex(const std::string& in);

View File

@ -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_view>
string transpile(const ParseTree& tree, const string_view& language);
#endif //YERBACON_MISC_HPP

View File

@ -2,6 +2,7 @@
#define YERBACON_PARSECOMPONENTS_HPP
#include <iostream>
#include <utility>
#include <vector>
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

View File

@ -0,0 +1,21 @@
#ifndef YERBACON_PARSER_HPP
#define YERBACON_PARSER_HPP
#include <string>
namespace Parser {
ParseTree parseVector(const vector<tok>& 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

View File

@ -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));
}

View File

@ -1,5 +1,4 @@
#include <iostream>
#include <string_view>
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);
}