diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-01 16:55:12 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-01 16:55:12 +0200 |
| commit | a78c432d6784665bb0211693e2dad96cc72f8445 (patch) | |
| tree | 6ecf19751ad4bc94c62e673f6bad323c3c9a5802 | |
| parent | fcf37e1243cf028f5812be81c9b1983d26d41874 (diff) | |
MHR-21: Working on a parsing algorithm for MHR-21.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | Headers/ParserKit.hpp | 20 | ||||
| -rw-r--r-- | Sources/64x0-cc.cc | 2 | ||||
| -rw-r--r-- | Sources/amd64-cplusplus.cc (renamed from Sources/ccplus.cc) | 94 | ||||
| -rw-r--r-- | Sources/ppc-cc.cc | 2 | ||||
| -rw-r--r-- | posix.make | 5 |
5 files changed, 43 insertions, 80 deletions
diff --git a/Headers/ParserKit.hpp b/Headers/ParserKit.hpp index 801d502..b7768e7 100644 --- a/Headers/ParserKit.hpp +++ b/Headers/ParserKit.hpp @@ -35,12 +35,32 @@ class CompilerBackend { struct SyntaxLeafList; struct SyntaxLeafList; +struct CompilerKeyword; + +/// we want to do that because to separate keywords. +enum { + eKeywordKindAccess, + eKeywordKindObject, + eKeywordKindDataType, + eKeywordKindCompilerAttribute, + eKeywordKindKeyword, +}; +/// \brief Compiler keyword information struct. +struct CompilerKeyword { + std::string keyword_name; + int32_t keyword_kind = eKeywordKindKeyword; +}; struct SyntaxLeafList final { struct SyntaxLeaf final { Int32 fUserType; +#ifdef __PK_USE_STRUCT_INSTEAD__ + CompilerKeyword fUserData; + CompilerKeyword fUserValue; +#else std::string fUserData; std::string fUserValue; +#endif struct SyntaxLeaf* fNext; }; diff --git a/Sources/64x0-cc.cc b/Sources/64x0-cc.cc index 7e6b116..de3eb65 100644 --- a/Sources/64x0-cc.cc +++ b/Sources/64x0-cc.cc @@ -1140,7 +1140,7 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface { (*kState.fOutputAssembly) << "# Path: " << src_file << "\n"; (*kState.fOutputAssembly) << "# Language: 64x0 Assembly (Generated from ANSI C)\n"; - (*kState.fOutputAssembly) << "# Build Date: " << fmt << "\n\n"; + (*kState.fOutputAssembly) << "# Date: " << fmt << "\n\n"; ParserKit::SyntaxLeafList syntax; diff --git a/Sources/ccplus.cc b/Sources/amd64-cplusplus.cc index e134db9..4c80d88 100644 --- a/Sources/ccplus.cc +++ b/Sources/amd64-cplusplus.cc @@ -9,11 +9,12 @@ /// bugs: 0 +#define __PK_USE_STRUCT_INSTEAD__ 1 + #define kPrintF printf -#define kSplashCxx() \ - kPrintF(kWhite "%s\n", \ - "Mahrouss C++ Compiler, Copyright Mahrouss Logic.") +#define kSplashCxx() \ + kPrintF(kWhite "%s\n", "Mahrouss C++ Compiler, Copyright Mahrouss Logic.") #include <Headers/AsmKit/CPU/amd64.hpp> #include <Headers/ParserKit.hpp> @@ -135,7 +136,7 @@ static size_t kRegisterCnt = kAsmRegisterLimit; static size_t kStartUsable = 8; static size_t kUsableLimit = 15; static size_t kRegisterCounter = kStartUsable; -static std::vector<std::string> kKeywords; +static std::vector<ParserKit::CompilerKeyword> kKeywords; ///////////////////////////////////////// @@ -162,7 +163,6 @@ class CompilerBackendCPlusPlus final : public ParserKit::CompilerBackend { bool Compile(const std::string& text, const char* file) override; const char* Language() override; - }; /// compiler variables @@ -182,7 +182,7 @@ union number_cast final { }; } // namespace detail -const char* CompilerBackendCPlusPlus::Language() override { return "C++"; } +const char* CompilerBackendCPlusPlus::Language() { return "C++"; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -191,7 +191,8 @@ const char* CompilerBackendCPlusPlus::Language() override { return "C++"; } ///////////////////////////////////////////////////////////////////////////////////////// -bool CompilerBackendCPlusPlus::Compile(const std::string& text, const char* file) { +bool CompilerBackendCPlusPlus::Compile(const std::string& text, + const char* file) { if (text.empty()) return false; // if (expr) @@ -200,27 +201,20 @@ bool CompilerBackendCPlusPlus::Compile(const std::string& text, const char* file std::size_t index = 0UL; - auto syntax_tree = ParserKit::SyntaxLeafList::SyntaxLeaf(); - - syntax_tree.fUserData = text; - kState.fSyntaxTree->fLeafList.emplace_back(syntax_tree); - - std::string text_cpy = text; - - std::vector<std::pair<std::string, std::size_t>> keywords_list; + std::vector<std::pair<ParserKit::CompilerKeyword, std::size_t>> keywords_list; for (auto& keyword : kKeywords) { - while (text_cpy.find(keyword) != std::string::npos) { + while (text.find(keyword.keyword_name) != std::string::npos) { keywords_list.emplace_back(std::make_pair(keyword, index)); ++index; - - text_cpy.erase(text_cpy.find(keyword), keyword.size()); } } // TODO: sort keywords for (auto& keyword : keywords_list) { + auto syntax_tree = ParserKit::SyntaxLeafList::SyntaxLeaf(); + syntax_tree.fUserData = keyword.first; kState.fSyntaxTree->fLeafList.emplace_back(syntax_tree); } @@ -276,9 +270,9 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyInterface { (*kState.fOutputAssembly) << "; Path: " << src_file << "\n"; (*kState.fOutputAssembly) - << "; Language: MultiProcessor Assembly. (Generated from C++)\n"; - (*kState.fOutputAssembly) << "; Build Date: " << fmt << "\n\n"; - (*kState.fOutputAssembly) << "#bits 64 " + << "; Language: CodeTools assembly. (Generated from C++)\n"; + (*kState.fOutputAssembly) << "; Date: " << fmt << "\n\n"; + (*kState.fOutputAssembly) << "#bits 64\n\n#org 0x1000000" << "\n\n"; ParserKit::SyntaxLeafList syntax; @@ -305,7 +299,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyInterface { static void cxx_print_help() { kSplashCxx(); kPrintF("%s", "No help available, see:\r\n"); - kPrintF("%s", "www.el-mahrouss-logic.com/tools/ccplus\r\n"); + kPrintF("%s", "www.el-mahrouss-logic.com/developer/newos/cplusplus\r\n"); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -314,62 +308,6 @@ static void cxx_print_help() { { ".cpp", ".cxx", ".cc", ".c++", ".cp" } MPCC_MODULE(CompilerCPlusPlus) { - kKeywords.emplace_back("auto"); - kKeywords.emplace_back("else"); - kKeywords.emplace_back("break"); - kKeywords.emplace_back("switch"); - kKeywords.emplace_back("enum"); - kKeywords.emplace_back("register"); - kKeywords.emplace_back("do"); - kKeywords.emplace_back("return"); - kKeywords.emplace_back("if"); - kKeywords.emplace_back("default"); - kKeywords.emplace_back("struct"); - kKeywords.emplace_back("_Packed"); - kKeywords.emplace_back("_Align"); - kKeywords.emplace_back("_AlignAs"); - kKeywords.emplace_back("extern"); - kKeywords.emplace_back("volatile"); - kKeywords.emplace_back("static"); - kKeywords.emplace_back("for"); - kKeywords.emplace_back("class"); - kKeywords.emplace_back("{"); - kKeywords.emplace_back("}"); - kKeywords.emplace_back("("); - kKeywords.emplace_back(")"); - kKeywords.emplace_back("char"); - kKeywords.emplace_back("int"); - kKeywords.emplace_back("short"); - kKeywords.emplace_back("long"); - kKeywords.emplace_back("float"); - kKeywords.emplace_back("double"); - kKeywords.emplace_back("unsigned"); - kKeywords.emplace_back("__attribute__"); - kKeywords.emplace_back("namespace"); - kKeywords.emplace_back("while"); - kKeywords.emplace_back("sizeof"); - kKeywords.emplace_back("private"); - kKeywords.emplace_back("->"); - kKeywords.emplace_back("."); - kKeywords.emplace_back("::"); - kKeywords.emplace_back("*"); - kKeywords.emplace_back("+"); - kKeywords.emplace_back("-"); - kKeywords.emplace_back("/"); - kKeywords.emplace_back("="); - kKeywords.emplace_back("=="); - kKeywords.emplace_back("!="); - kKeywords.emplace_back(">="); - kKeywords.emplace_back("<="); - kKeywords.emplace_back(">"); - kKeywords.emplace_back("<"); - kKeywords.emplace_back(":"); - kKeywords.emplace_back(","); - kKeywords.emplace_back(";"); - kKeywords.emplace_back("&"); - kKeywords.emplace_back("public"); - kKeywords.emplace_back("protected"); - bool skip = false; kFactory.Mount(new AssemblyMountpointClang()); diff --git a/Sources/ppc-cc.cc b/Sources/ppc-cc.cc index 3667ca2..0dfdbc2 100644 --- a/Sources/ppc-cc.cc +++ b/Sources/ppc-cc.cc @@ -1157,7 +1157,7 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyInterface { (*kState.fOutputAssembly) << "# Path: " << src_file << "\n"; (*kState.fOutputAssembly) << "# Language: POWER Assembly (Generated from C)\n"; - (*kState.fOutputAssembly) << "# Build Date: " << fmt << "\n\n"; + (*kState.fOutputAssembly) << "# Date: " << fmt << "\n\n"; ParserKit::SyntaxLeafList syntax; @@ -20,6 +20,10 @@ PP_OUTPUT=Output/bpp.exec SRC_COMMON=Sources/String.cc Sources/AsmKit.cc +# C++ Compiler (AMD64) +AMD64_CXX_SRC=Sources/amd64-cplusplus.cc $(SRC_COMMON) +AMD64_CXX_OUTPUT=Output/amd64-cplusplus.exec + # C Compiler (POWER) 64X0_CC_SRC=Sources/64x0-cc.cc $(SRC_COMMON) 64X0_CC_OUTPUT=Output/64x0-cc.exec @@ -51,6 +55,7 @@ pre-processor: .PHONY: compiler compiler: $(LINK_CC) $(COMMON_INC) $(64X0_CC_SRC) -o $(64X0_CC_OUTPUT) + $(LINK_CC) $(COMMON_INC) $(AMD64_CXX_SRC) -o $(AMD64_CXX_OUTPUT) $(LINK_CC) $(COMMON_INC) $(PPC_CC_SRC) -o $(PPC_CC_OUTPUT) $(LINK_CC) $(COMMON_INC) $(IASM_SRC) -o $(IASM_OUTPUT) $(LINK_CC) $(COMMON_INC) $(ASM_SRC) -o $(ASM_OUTPUT) |
