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 /Sources | |
| parent | fcf37e1243cf028f5812be81c9b1983d26d41874 (diff) | |
MHR-21: Working on a parsing algorithm for MHR-21.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Sources')
| -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 |
3 files changed, 18 insertions, 80 deletions
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; |
