code_compiler: Add initial Compiler and Parser

These don't do much yet and are just here so the class structure exists.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2017-11-13 02:16:17 +01:00
parent 34a227d2ff
commit dcd8950260
5 changed files with 181 additions and 0 deletions
+6
View File
@@ -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"
@@ -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 <https://www.gnu.org/licenses/>.
#include "compiler.hpp"
#include "parser.hpp"
#include "lexer.hpp"
#include <fstream>
#include <iostream>
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;
}
@@ -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 <https://www.gnu.org/licenses/>.
#pragma once
#include <string>
namespace BlitzLLVM {
class Compiler {
public:
Compiler();
~Compiler();
bool Compile(std::string in, std::string out);
private:
};
}
+26
View File
@@ -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 <https://www.gnu.org/licenses/>.
#include "parser.hpp"
BlitzLLVM::Parser::Parser(std::istream& in) : m_lexer(in) {
}
BlitzLLVM::Parser::~Parser() {
}
+32
View File
@@ -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 <https://www.gnu.org/licenses/>.
#pragma once
#include "lexer.hpp"
#include <istream>
namespace BlitzLLVM {
class Parser {
public:
Parser(std::istream& in);
~Parser();
private:
Lexer m_lexer;
};
}