From dcd8950260f9d2e1797551f0a047e75203e77c93 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Mon, 13 Nov 2017 02:16:17 +0100 Subject: [PATCH] code_compiler: Add initial Compiler and Parser These don't do much yet and are just here so the class structure exists. --- projects/code_compiler/CMakeLists.txt | 6 ++ projects/code_compiler/source/compiler.cpp | 87 ++++++++++++++++++++++ projects/code_compiler/source/compiler.hpp | 30 ++++++++ projects/code_compiler/source/parser.cpp | 26 +++++++ projects/code_compiler/source/parser.hpp | 32 ++++++++ 5 files changed, 181 insertions(+) create mode 100644 projects/code_compiler/source/compiler.cpp create mode 100644 projects/code_compiler/source/compiler.hpp create mode 100644 projects/code_compiler/source/parser.cpp create mode 100644 projects/code_compiler/source/parser.hpp diff --git a/projects/code_compiler/CMakeLists.txt b/projects/code_compiler/CMakeLists.txt index 4c3c8a9..60f8dbb 100644 --- a/projects/code_compiler/CMakeLists.txt +++ b/projects/code_compiler/CMakeLists.txt @@ -19,6 +19,12 @@ INCLUDE("CMakeVersion.txt") # Source Files SET(SOURCE "source/main.cpp" + "source/lexer.hpp" + "source/lexer.cpp" + "source/parser.hpp" + "source/parser.cpp" + "source/compiler.hpp" + "source/compiler.cpp" ) SET(DATA "CMakeVersion.txt" diff --git a/projects/code_compiler/source/compiler.cpp b/projects/code_compiler/source/compiler.cpp new file mode 100644 index 0000000..186d529 --- /dev/null +++ b/projects/code_compiler/source/compiler.cpp @@ -0,0 +1,87 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#include "compiler.hpp" +#include "parser.hpp" +#include "lexer.hpp" +#include +#include + +BlitzLLVM::Compiler::Compiler() {} + +BlitzLLVM::Compiler::~Compiler() {} + +bool BlitzLLVM::Compiler::Compile(std::string in, std::string out) { + std::ifstream infile; + infile.open(in); + if (infile.bad() || !infile.good() || infile.eof()) { + std::cerr << "Failed to open file: " << in << std::endl; + return false; + } + + Lexer psr = { infile }; + for (auto tkn = psr.GetNextToken(); tkn.first != Lexer::Token::TokenEOF; tkn = psr.GetNextToken()) { + switch (tkn.first) { + case Lexer::Token::TokenEOF: + std::cout << "EOF" << std::endl; + break; + case Lexer::Token::TokenNewLine: + std::cout << "NewLine" << std::endl; + break; + case Lexer::Token::TokenPlus: + case Lexer::Token::TokenMinus: + case Lexer::Token::TokenSlashForward: + case Lexer::Token::TokenSlashBackward: + case Lexer::Token::TokenMultiply: + case Lexer::Token::TokenEqual: + case Lexer::Token::TokenOctothorp: + case Lexer::Token::TokenPercent: + case Lexer::Token::TokenDollar: + case Lexer::Token::TokenRoundBracketOpen: + case Lexer::Token::TokenRoundBracketClose: + case Lexer::Token::TokenSquareBracketOpen: + case Lexer::Token::TokenSquareBracketClose: + case Lexer::Token::TokenAngleBracketOpen: + case Lexer::Token::TokenAngleBracketClose: + case Lexer::Token::TokenDot: + case Lexer::Token::TokenColon: + case Lexer::Token::TokenComma: + case Lexer::Token::TokenSemicolon: + case Lexer::Token::TokenCaret: + case Lexer::Token::TokenDoubleQuote: + std::cout << tkn.second << ' '; + break; + case Lexer::Token::TokenText: + std::cout << "Text(" << tkn.second << ")" << ' '; + break; + case Lexer::Token::TokenNumber: + std::cout << "Number(" << tkn.second << ")" << ' '; + break; + case Lexer::Token::TokenDecimal: + std::cout << "Decimal(" << tkn.second << ")" << ' '; + break; + case Lexer::Token::TokenQuotedText: + std::cout << "QuotedText(" << tkn.second << ")" << ' '; + break; + case Lexer::Token::TokenUnknown: + default: + std::cout << "Unknown" << std::endl; + break; + } + } + + return true; +} diff --git a/projects/code_compiler/source/compiler.hpp b/projects/code_compiler/source/compiler.hpp new file mode 100644 index 0000000..d7bc93f --- /dev/null +++ b/projects/code_compiler/source/compiler.hpp @@ -0,0 +1,30 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#pragma once +#include + +namespace BlitzLLVM { + class Compiler { + public: + Compiler(); + ~Compiler(); + + bool Compile(std::string in, std::string out); + + private: + }; +} \ No newline at end of file diff --git a/projects/code_compiler/source/parser.cpp b/projects/code_compiler/source/parser.cpp new file mode 100644 index 0000000..dec16db --- /dev/null +++ b/projects/code_compiler/source/parser.cpp @@ -0,0 +1,26 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#include "parser.hpp" + +BlitzLLVM::Parser::Parser(std::istream& in) : m_lexer(in) { + +} + +BlitzLLVM::Parser::~Parser() { + +} + diff --git a/projects/code_compiler/source/parser.hpp b/projects/code_compiler/source/parser.hpp new file mode 100644 index 0000000..050f63d --- /dev/null +++ b/projects/code_compiler/source/parser.hpp @@ -0,0 +1,32 @@ +// Code Compiler for BlitzLLVM +// Copyright(C) 2017 Michael Fabian Dirks +// +// This program is free software : you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.If not, see . + +#pragma once +#include "lexer.hpp" +#include + +namespace BlitzLLVM { + class Parser { + public: + Parser(std::istream& in); + ~Parser(); + + + + private: + Lexer m_lexer; + }; +} \ No newline at end of file