Update to modern standard i guess

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2024-06-06 13:37:13 +02:00
parent ade728ec31
commit 4e2dd8e30b
29 changed files with 828 additions and 378 deletions
+10
View File
@@ -2,3 +2,13 @@
/build /build
/build32 /build32
/build64 /build64
/tests/*.zip
/tests/*.jpg
/tests/*.jpeg
/tests/*.png
/tests/*.bmp
/tests/*.tga
/tests/*.exe
/tests/*.dll
/tests/*.bin
/tests/*.dat
+6
View File
@@ -0,0 +1,6 @@
[submodule "cmake/cmake-version"]
path = cmake/cmake-version
url = https://github.com/Xaymar/cmake-version.git
[submodule "cmake/cmake-clang"]
path = cmake/cmake-clang
url = https://github.com/Xaymar/cmake-clang.git
+175 -2
View File
@@ -1,4 +1,177 @@
cmake_minimum_required(VERSION 2.8.12) ################################################################################
# CMake Setup
################################################################################
cmake_minimum_required(VERSION 3.26...)
project(BlitzLLVM) project(BlitzLLVM)
list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ")
ADD_SUBDIRECTORY("projects/code_compiler") # Module Search Paths
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-clang"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-version"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)
# Include default modules
#- Interprocedural optimizations
include("CheckIPOSupported")
#- CMake-based Versioning
include("version")
#- CMake-based Clang integration
include("clang")
SET_PROPERTY( GLOBAL PROPERTY USE_FOLDERS ON)
################################################################################
# Versioning
################################################################################
version(GENERATE _VERSION COMPRESSED MAJOR 0 MINOR 0 PATCH 0 TWEAK 0 REQUIRE "PATCH;")
version(PARSE _VERSION "${_VERSION}" REQUIRE "PATCH;TWEAK")
# If possible, automatically generate versions from git.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
find_program(GIT
NAMES
git
git.exe
)
if(EXISTS "${GIT}")
# Try and calculate the exist version using git.
execute_process(COMMAND "${GIT}" describe --tags --long --abbrev=8 HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL ""))
# Result will be MAJOR.MINOR.PATCH-TWEAK-gHASH
string(REPLACE "-" ";" GIT_OUTPUT "${GIT_OUTPUT}")
string(REPLACE "." ";" GIT_OUTPUT "${GIT_OUTPUT}")
# Split into components
list(GET GIT_OUTPUT 0 GIT_OUTPUT_MAJOR)
list(GET GIT_OUTPUT 1 GIT_OUTPUT_MINOR)
list(GET GIT_OUTPUT 2 GIT_OUTPUT_PATCH)
list(GET GIT_OUTPUT 3 GIT_OUTPUT_TWEAK)
list(GET GIT_OUTPUT 4 GIT_OUTPUT_BUILD)
# Special case: Tag contains prerelease
if(GIT_OUTPUT_PATCH MATCHES "([0-9]+)([a-zA-Z]+)([0-9]*)")
# Patch requires special parsing.
set(GIT_OUTPUT_PATCH "${CMAKE_MATCH_1}")
if(CMAKE_MATCH_3 GREATER 0)
set(GIT_OUTPUT_PRERELEASE "${CMAKE_MATCH_2}")
else()
set(GIT_OUTPUT_PRERELEASE "a")
endif()
MATH(EXPR GIT_OUTPUT_TWEAK "${GIT_OUTPUT_TWEAK} + ${CMAKE_MATCH_3}")
# Modify the global version
version(MODIFY _VERSION "${_VERSION}" COMPRESS
MAJOR "${GIT_OUTPUT_MAJOR}"
MINOR "${GIT_OUTPUT_MINOR}"
PATCH "${GIT_OUTPUT_PATCH}"
TWEAK "${GIT_OUTPUT_TWEAK}"
BUILD "${GIT_OUTPUT_BUILD}"
PRERELEASE "${GIT_OUTPUT_PRERELEASE}"
REQUIRE "PATCH;TWEAK"
)
else()
# Modify the global version
version(MODIFY _VERSION "${_VERSION}" COMPRESS
MAJOR "${GIT_OUTPUT_MAJOR}"
MINOR "${GIT_OUTPUT_MINOR}"
PATCH "${GIT_OUTPUT_PATCH}"
TWEAK "${GIT_OUTPUT_TWEAK}"
BUILD "${GIT_OUTPUT_BUILD}"
PRERELEASE "a"
REQUIRE "PATCH;TWEAK"
)
endif()
else()
execute_process(COMMAND "${GIT}" rev-list --count HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL ""))
version(MODIFY _VERSION "${_VERSION}" COMPRESS
TWEAK "${GIT_OUTPUT}"
PRERELEASE "a"
REQUIRE "PATCH;TWEAK"
)
# Determine the build using git.
execute_process(COMMAND "${GIT}" log -1 "--pretty=format:g%h" --abbrev=8 HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT ERROR_VARIABLE GIT_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if((GIT_RESULT EQUAL 0) AND (NOT "${GIT_OUTPUT}" STREQUAL ""))
version(MODIFY _VERSION "${_VERSION}" COMPRESS
BUILD "${GIT_OUTPUT}"
REQUIRE "PATCH;TWEAK"
)
else()
message(WARNING "Failed to detect build version with 'git'.")
endif()
else()
message(WARNING "Failed to automatically detect version with 'git'.")
endif()
endif()
else()
message(WARNING "'git' not found, automatic version detection disabled.")
endif()
else()
message(STATUS "Not a git repository, automatic version detection disabled.")
endif()
# Allow manual overrides of the detected version.
if(${PREFIX}VERSION)
version(PARSE _VERSION_CFG "${${PREFIX}VERSION}" REQUIRE "PATCH;TWEAK")
if("${_VERSION_CFG_BUILD}" STREQUAL "")
set(_VERSION_CFG_BUILD "${_VERSION_BUILD}")
endif()
version(GENERATE _VERSION COMPRESS
MAJOR "${_VERSION_CFG_MAJOR}"
MINOR "${_VERSION_CFG_MINOR}"
PATCH "${_VERSION_CFG_PATCH}"
TWEAK "${_VERSION_CFG_TWEAK}"
PRERELEASE "${_VERSION_CFG_PRERELEASE}"
BUILD "${_VERSION_CFG_BUILD}"
)
endif()
# Fix up missing parts of the Version
version(PARSE _VERSION "${_VERSION}" REQUIRE "PATCH;TWEAK")
set(_VERSION_THIN "${_VERSION_MAJOR}.${_VERSION_MINOR}.${_VERSION_PATCH}")
if(NOT (_VERSION_PRERELEASE STREQUAL ""))
set(_VERSION_THIN "${_VERSION_THIN}${_VERSION_PRERELEASE}${_VERSION_TWEAK}")
endif()
if(NOT (VERSION_COMMIT STREQUAL ""))
set(_VERSION_THIN "${_VERSION_THIN}-${_VERSION_BUILD}")
endif()
# Parse & Log the detected version.
message(STATUS "Version ${_VERSION_THIN}")
################################################################################
# Project
################################################################################
# Metadata
version(GENERATE PROJECT_VERSION
MAJOR "${_VERSION_MAJOR}"
MINOR "${_VERSION_MINOR}"
PATCH "${_VERSION_PATCH}"
TWEAK "${_VERSION_TWEAK}"
REQUIRE "PATCH;TWEAK"
)
project(
${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
)
set(PROJECT_IDENTIFER "com.xaymar.BlitzLLVM")
set(PROJECT_TITLE "BlitzLLVM")
set(PROJECT_AUTHORS "See AUTHORS file")
set(PROJECT_COPYRIGHT "All Rights Reserved. See LICENSE file for more information")
set(PROJECT_TRADEMARKS "")
################################################################################
# Sub-projects
################################################################################
ADD_SUBDIRECTORY("code_compiler")
-165
View File
@@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
+9
View File
@@ -0,0 +1,9 @@
Copyright 2014-2024 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+2
View File
@@ -0,0 +1,2 @@
== What is BlitzLLVM?
BlitzLLVM is an attempt at a functional transpiler for BlitzBasic (Blitz2D, Blitz3D, and BlitzPlus).
+1
Submodule cmake/cmake-clang added at 654f2bcc20
Submodule cmake/cmake-version added at 3bef96bafa
@@ -1,16 +1,17 @@
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 3.0.2)
project(CodeCompiler) project(CodeCompiler)
# Configuration # Configuration
## Dependencies ## Dependencies
# LLVM # LLVM
find_package(LLVM REQUIRED CONFIG) #find_package(LLVM REQUIRED CONFIG)
llvm_map_components_to_libnames(llvm_libs support core irreader) #llvm_map_components_to_libnames(llvm_libs support core irreader)
# Boost # Boost
SET(Boost_USE_STATIC_LIBS ON) #SET(BOOST_ROOT "" CACHE PATH "Path to Boost")
find_package(Boost REQUIRED COMPONENTS program_options) #SET(Boost_USE_STATIC_LIBS ON)
#find_package(Boost REQUIRED COMPONENTS program_options)
## Version ## Version
INCLUDE("CMakeVersion.txt") INCLUDE("CMakeVersion.txt")
@@ -21,6 +22,14 @@ SET(SOURCE
"source/main.cpp" "source/main.cpp"
"source/lexer.hpp" "source/lexer.hpp"
"source/lexer.cpp" "source/lexer.cpp"
"source/ast/ast.hpp"
"source/ast/ast.cpp"
"source/ast/arithmetic.hpp"
"source/ast/arithmetic.cpp"
"source/ast/function.hpp"
"source/ast/function.cpp"
"source/ast/value.hpp"
"source/ast/value.cpp"
"source/parser.hpp" "source/parser.hpp"
"source/parser.cpp" "source/parser.cpp"
"source/compiler.hpp" "source/compiler.hpp"
@@ -30,6 +39,9 @@ SET(DATA
"CMakeVersion.txt" "CMakeVersion.txt"
) )
# Source Grouping
SOURCE_GROUP(TREE ${PROJECT_SOURCE_DIR}/source PREFIX Source FILES ${SOURCE})
# Definitions # Definitions
ADD_DEFINITIONS( ADD_DEFINITIONS(
${LLVM_DEFINITIONS} ${LLVM_DEFINITIONS}
+22
View File
@@ -0,0 +1,22 @@
// 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 "arithmetic.hpp"
BlitzLLVM::AST::ArithmeticExpression::ArithmeticExpression(Operator op, std::unique_ptr<Expression> left, std::unique_ptr<Expression> right)
: m_operator(op), m_left(std::move(left)), m_right(std::move(right)) {}
BlitzLLVM::AST::ArithmeticExpression::~ArithmeticExpression() {}
+43
View File
@@ -0,0 +1,43 @@
// 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 "ast.hpp"
#include "value.hpp"
namespace BlitzLLVM {
namespace AST {
enum class Operator : int8_t {
Add, /*+*/
Subtract, /*-*/
Multiply, /***/
Divide, /*/*/
Invert, /*~*/
Power, /*^*/
Equal, /*=*/
};
class ArithmeticExpression : public Expression {
public:
ArithmeticExpression(Operator op, std::unique_ptr<Expression> left, std::unique_ptr<Expression> right);
virtual ~ArithmeticExpression();
private:
Operator m_operator;
std::unique_ptr<Expression> m_left, m_right;
};
}
}
@@ -14,19 +14,4 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>. // along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #include "ast.hpp"
#include "lexer.hpp"
#include <istream>
namespace BlitzLLVM {
class Parser {
public:
Parser(std::istream& in);
~Parser();
private:
Lexer m_lexer;
};
}
@@ -14,13 +14,13 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program.If not, see <https://www.gnu.org/licenses/>. // along with this program.If not, see <https://www.gnu.org/licenses/>.
#include "parser.hpp" #pragma once
BlitzLLVM::Parser::Parser(std::istream& in) : m_lexer(in) {
namespace BlitzLLVM {
namespace AST {
class Expression {
public:
virtual ~Expression() {};
};
}
} }
BlitzLLVM::Parser::~Parser() {
}
View File
View File
+42
View File
@@ -0,0 +1,42 @@
// 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 "function.hpp"
BlitzLLVM::AST::ScopeExpression::ScopeExpression() {}
BlitzLLVM::AST::ScopeExpression::~ScopeExpression() {}
void BlitzLLVM::AST::ScopeExpression::AddExpression(std::unique_ptr<Expression> ex) {
m_expressions.push_back(std::move(ex));
}
BlitzLLVM::AST::FunctionExpression::FunctionExpression(ValueType returnType,
std::string& m_name,
std::list<std::unique_ptr<VariableExpression>> parameters,
std::unique_ptr<ScopeExpression> scope)
: m_returnType(returnType), m_name(m_name), m_parameters(std::move(parameters)), m_content(std::move(scope)) {
}
BlitzLLVM::AST::FunctionExpression::~FunctionExpression() {}
BlitzLLVM::AST::CallExpression::CallExpression(std::string& name, std::list<std::unique_ptr<VariableExpression>> arguments)
: m_name(name), m_arguments(std::move(arguments)) {
}
BlitzLLVM::AST::CallExpression::~CallExpression() {}
+63
View File
@@ -0,0 +1,63 @@
// 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 "ast.hpp"
#include "value.hpp"
#include <list>
#include <memory>
#include <string>
namespace BlitzLLVM {
namespace AST {
class ScopeExpression : public Expression {
public:
ScopeExpression();
virtual ~ScopeExpression();
void AddExpression(std::unique_ptr<Expression> ex);
private:
std::list<std::unique_ptr<Expression>> m_expressions;
};
class FunctionExpression : public ScopeExpression {
public:
FunctionExpression(ValueType returnType,
std::string& m_name,
std::list<std::unique_ptr<VariableExpression>> parameters,
std::unique_ptr<ScopeExpression> scope);
virtual ~FunctionExpression();
private:
ValueType m_returnType;
std::string m_name;
std::list<std::unique_ptr<VariableExpression>> m_parameters;
std::unique_ptr<ScopeExpression> m_content;
};
class CallExpression : public Expression {
public:
CallExpression(std::string& name, std::list<std::unique_ptr<VariableExpression>> arguments);
virtual ~CallExpression();
private:
std::string m_name;
std::list<std::unique_ptr<VariableExpression>> m_arguments;
};
}
}
+59
View File
@@ -0,0 +1,59 @@
// 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 "value.hpp"
BlitzLLVM::AST::VariableExpression::VariableExpression(std::string& name, ValueType type /*= ValueType::Number*/)
: m_name(name), m_type(type) {}
BlitzLLVM::AST::VariableExpression::~VariableExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::VariableExpression::GetType() {
return m_type;
}
BlitzLLVM::AST::NumberExpression::NumberExpression(int32_t value) : value(value) {}
BlitzLLVM::AST::NumberExpression::~NumberExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::NumberExpression::GetType() {
return ValueType::Number;
}
BlitzLLVM::AST::DecimalExpression::DecimalExpression(float_t value) : value(value) {}
BlitzLLVM::AST::DecimalExpression::~DecimalExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::DecimalExpression::GetType() {
return ValueType::Decimal;
}
BlitzLLVM::AST::StringExpression::StringExpression(std::string value) : value(value) {}
BlitzLLVM::AST::StringExpression::~StringExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::StringExpression::GetType() {
return ValueType::String;
}
BlitzLLVM::AST::ConstExpression::ConstExpression(std::string& name, std::unique_ptr<ValueExpression> value)
: m_name(name), m_value(std::move(value)) {}
BlitzLLVM::AST::ConstExpression::~ConstExpression() {}
BlitzLLVM::AST::ValueType BlitzLLVM::AST::ConstExpression::GetType() {
return m_value->GetType();
}
+98
View File
@@ -0,0 +1,98 @@
// 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 "ast.hpp"
#include "lexer.hpp"
#include <inttypes.h>
#include <float.h>
#include <math.h>
#include <memory>
#include <string>
namespace BlitzLLVM {
namespace AST {
enum class ValueType : int8_t {
Unknown,
Number,
Decimal,
String,
Type,
};
class ValueExpression : public Expression {
public:
virtual ValueType GetType() = 0;
};
class ConstExpression : public ValueExpression {
public:
ConstExpression(std::string& name, std::unique_ptr<ValueExpression> value);
virtual ~ConstExpression();
virtual ValueType GetType() override;
private:
std::string m_name;
std::unique_ptr<ValueExpression> m_value;
};
class VariableExpression : public ValueExpression {
public:
VariableExpression(std::string& name, ValueType type = ValueType::Number);
virtual ~VariableExpression();
virtual ValueType GetType() override;
private:
std::string m_name;
ValueType m_type;
};
class NumberExpression : public ValueExpression {
public:
NumberExpression(int32_t value);
virtual ~NumberExpression();
virtual ValueType GetType() override;
private:
int32_t value;
};
class DecimalExpression : public ValueExpression {
public:
DecimalExpression(float_t value);
virtual ~DecimalExpression();
virtual ValueType GetType() override;
private:
float_t value;
};
class StringExpression : public ValueExpression {
public:
StringExpression(std::string value);
virtual ~StringExpression();
virtual ValueType GetType() override;
private:
std::string value;
};
}
}
+41
View File
@@ -0,0 +1,41 @@
// 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;
}*/
Parser psr = Parser(in);
if (!psr.Parse()) {
}
return true;
}
@@ -43,11 +43,15 @@ std::pair<char, BlitzLLVM::Lexer::Token> g_symbolCharacters[] = {
{ '~', BlitzLLVM::Lexer::Token::TokenBitNot }, { '~', BlitzLLVM::Lexer::Token::TokenBitNot },
}; };
BlitzLLVM::Lexer::Lexer(std::istream& fs) : m_fileStream(fs) {} BlitzLLVM::Lexer::Lexer() {}
BlitzLLVM::Lexer::~Lexer() {} BlitzLLVM::Lexer::~Lexer() {}
std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken() { std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetCurrentToken() {
return std::make_pair(m_currentToken, m_currentText);
}
std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken(std::shared_ptr<std::istream> fs) {
std::string buf; std::string buf;
Token tkn = Token::TokenEOF; Token tkn = Token::TokenEOF;
bool haveResult = false; bool haveResult = false;
@@ -60,8 +64,13 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken()
haveResult = true; haveResult = true;
} }
while (((m_fileStream.eof() == false) && (m_fileStream.good())) && !haveResult) { bool m_isTextMode = false;
char chr = m_fileStream.get(); bool m_isNumberMode = false;
bool m_isStringMode = false;
bool m_isCommentMode = false;
bool m_numberModeHasDecimal = false;
while (((fs->eof() == false) && (fs->good())) && !haveResult) {
char chr = fs->get();
if (chr == '\r' || chr == '\n') { if (chr == '\r' || chr == '\n') {
if (tkn != Token::TokenEOF) { if (tkn != Token::TokenEOF) {
@@ -85,7 +94,7 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken()
tkn = Token::TokenQuotedText; tkn = Token::TokenQuotedText;
break; break;
} else if (iscntrl(chr) || !isprint(chr)) { } else if (iscntrl(chr) || !isprint(chr)) {
m_fileStream.putback(chr); fs->putback(chr);
m_isStringMode = false; m_isStringMode = false;
break; break;
} else { } else {
@@ -95,7 +104,7 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken()
if (isalnum(chr) || (chr == '_')) { if (isalnum(chr) || (chr == '_')) {
buf += chr; buf += chr;
} else { } else {
m_fileStream.putback(chr); fs->putback(chr);
m_isTextMode = false; m_isTextMode = false;
break; break;
} }
@@ -108,12 +117,12 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken()
tkn = Token::TokenDecimal; tkn = Token::TokenDecimal;
buf += chr; buf += chr;
} else { } else {
m_fileStream.putback(chr); fs->putback(chr);
m_isNumberMode = false; m_isNumberMode = false;
break; break;
} }
} else { } else {
m_fileStream.putback(chr); fs->putback(chr);
m_isNumberMode = false; m_isNumberMode = false;
break; break;
} }
@@ -131,6 +140,26 @@ std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Lexer::GetNextToken()
buf = chr; buf = chr;
} }
// Special handling for + and -, due to numbers and decimals.
if (chr == '+' || chr == '-') {
char chr2 = fs->get();
if (isdigit(chr2)) {
m_isNumberMode = true;
m_numberModeHasDecimal = false;
tkn = Token::TokenNumber;
buf = chr + chr2;
break;
} else if (chr2 == '.') {
m_isNumberMode = true;
m_numberModeHasDecimal = true;
tkn = Token::TokenDecimal;
buf = chr + "0" + chr2;
break;
} else {
fs->putback(chr2);
}
}
// Symbol // Symbol
for (auto v : g_symbolCharacters) { for (auto v : g_symbolCharacters) {
if (v.first == chr) { if (v.first == chr) {
@@ -15,10 +15,11 @@
// along with this program.If not, see <https://www.gnu.org/licenses/>. // along with this program.If not, see <https://www.gnu.org/licenses/>.
#pragma once #pragma once
#include <list>
#include <istream>
#include <string>
#include <inttypes.h> #include <inttypes.h>
#include <istream>
#include <memory>
#include <string>
#include <utility>
namespace BlitzLLVM { namespace BlitzLLVM {
class Lexer { class Lexer {
@@ -108,23 +109,18 @@ namespace BlitzLLVM {
}; };
public: public:
Lexer(std::istream& fs); Lexer();
~Lexer(); ~Lexer();
std::pair<Token, std::string> GetNextToken(); std::pair<Token, std::string> GetCurrentToken();
std::pair<Token, std::string> GetNextToken(std::shared_ptr<std::istream> fs);
private: private:
BlitzLLVM::Lexer::Token ConvertTextToToken(Token in, std::string text); BlitzLLVM::Lexer::Token ConvertTextToToken(Token in, std::string text);
private: private:
std::istream& m_fileStream; Token m_currentToken = Token::TokenUnknown;
std::string m_currentText = "";
bool m_isTextMode = false;
bool m_isNumberMode = false;
bool m_isStringMode = false;
bool m_isCommentMode = false;
bool m_numberModeHasDecimal = false;
Token m_overrideToken = Token::TokenUnknown; Token m_overrideToken = Token::TokenUnknown;
std::string m_overrideText = ""; std::string m_overrideText = "";
}; };
@@ -20,7 +20,8 @@
#include "version.h" #include "version.h"
#define LICENSE "Copyright (C) 2017 Michael Fabian Dirks\n\ #define LICENSE "Copyright (C) 2017 Michael Fabian Dirks\n\
This program comes with ABSOLUTELY NO WARRANTY, for details launch with `--warranty`. This is free software, and you are welcome to redistribute it under certain conditions." This program comes with ABSOLUTELY NO WARRANTY, for details launch with `--warranty`.\n\
This is free software, and you are welcome to redistribute it under certain conditions."
#define WARRANTY "\ #define WARRANTY "\
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.EXCEPT WHEN OTHERWISE STATED IN \ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.EXCEPT WHEN OTHERWISE STATED IN \
+125
View File
@@ -0,0 +1,125 @@
// 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"
#include "ast/function.hpp"
#include <iostream>
#include <vector>
#include <stdarg.h>
BlitzLLVM::Parser::Parser(std::string file) {
// Try and load the file
std::shared_ptr<std::ifstream> instream = std::make_shared<std::ifstream>(file);
if (instream->bad() || !instream->good()) {
throw std::ios_base::failure("Failed to open file.");
}
m_files.push(std::make_pair(file, instream));
}
BlitzLLVM::Parser::~Parser() {
while (m_files.size() > 0) {
std::shared_ptr<std::ifstream> file = std::dynamic_pointer_cast<std::ifstream>(m_files.top().second);
file->close();
m_files.pop();
}
}
std::unique_ptr<BlitzLLVM::AST::Expression> BlitzLLVM::Parser::Parse() {
std::unique_ptr<AST::ScopeExpression> scope = std::make_unique<AST::ScopeExpression>();
std::unique_ptr<AST::Expression> expr;
while ((expr = std::move(ParseExpression())) != nullptr) {
scope->AddExpression(std::move(expr));
}
return std::move(scope);
}
void BlitzLLVM::Parser::LogMessage(const char* msg, ...) {
std::vector<char> buf(65535);
va_list val;
va_start(val, msg);
int rval = vsnprintf(buf.data(), buf.size(), msg, val);
va_end(val);
std::cout << buf.data() << '\n';
}
void BlitzLLVM::Parser::LogError(const char* msg, ...) {
std::vector<char> buf(65535);
va_list val;
va_start(val, msg);
int rval = vsnprintf(buf.data(), buf.size(), msg, val);
va_end(val);
std::cerr << buf.data() << '\n';
}
std::pair<BlitzLLVM::Lexer::Token, std::string> BlitzLLVM::Parser::GetNextToken() {
return m_lexer.GetNextToken(m_files.top().second);
}
std::unique_ptr<BlitzLLVM::AST::Expression> BlitzLLVM::Parser::ParseExpression() {
while (true) {
auto tkn = GetNextToken();
switch (tkn.first) {
case BlitzLLVM::Lexer::Token::TokenNewLine:
case BlitzLLVM::Lexer::Token::TokenComment:
// Skip Comments, since we don't really need them for the AST.
continue;
case BlitzLLVM::Lexer::Token::TokenPlus:
case BlitzLLVM::Lexer::Token::TokenMinus:
default: // End Of File / Unknown
case BlitzLLVM::Lexer::Token::TokenUnknown:
case BlitzLLVM::Lexer::Token::TokenEOF:
return nullptr;
break;
}
}
}
std::unique_ptr<BlitzLLVM::AST::NumberExpression> BlitzLLVM::Parser::ParseNumber(BlitzLLVM::Lexer::Token token, std::string value) {
if (token != Lexer::Token::TokenNumber) {
LogError("Unexpected Token during parsing, expected number.");
return nullptr;
}
char* endptr = const_cast<char*>(value.c_str() + value.size());
int32_t parsed = strtol(value.c_str(), &endptr, 10);
if (errno == ERANGE) {
LogError("Number out of range.");
return nullptr;
}
return std::make_unique<BlitzLLVM::AST::NumberExpression>(parsed);
}
std::unique_ptr<BlitzLLVM::AST::DecimalExpression> BlitzLLVM::Parser::ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value) {
if (token != Lexer::Token::TokenNumber) {
LogError("Unexpected Token during parsing, expected number.");
return nullptr;
}
char* endptr = const_cast<char*>(value.c_str() + value.size());
float_t parsed = strtof(value.c_str(), &endptr);
if (errno == ERANGE) {
LogError("Number out of range.");
return nullptr;
}
return std::make_unique<BlitzLLVM::AST::DecimalExpression>(parsed);
}
+52
View File
@@ -0,0 +1,52 @@
// 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 "ast/ast.hpp"
#include "ast/value.hpp"
#include <fstream>
#include <map>
#include <memory>
#include <string>
#include <stack>
namespace BlitzLLVM {
class Parser {
public:
Parser(std::string file);
~Parser();
std::unique_ptr<AST::Expression> Parse();
protected:
void LogMessage(const char* msg, ...);
void LogError(const char* msg, ...);
private:
std::pair<BlitzLLVM::Lexer::Token, std::string> GetNextToken();
private:
std::unique_ptr<AST::Expression> ParseExpression();
std::unique_ptr<AST::NumberExpression> ParseNumber(BlitzLLVM::Lexer::Token token, std::string value);
std::unique_ptr<AST::DecimalExpression> ParseDecimal(BlitzLLVM::Lexer::Token token, std::string value);
private:
Lexer m_lexer;
std::stack<std::pair<std::string, std::shared_ptr<std::istream>>> m_files;
};
}
-7
View File
@@ -1,7 +0,0 @@
SET(VERSION_MAJOR 0)
SET(VERSION_MINOR 0)
SET(VERSION_PATCH 1)
configure_file(
"${PROJECT_SOURCE_DIR}/templates/version.h"
"${PROJECT_BINARY_DIR}/version.h"
)
-148
View File
@@ -1,148 +0,0 @@
// 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 << "" << 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::TokenBitNot:
case Lexer::Token::TokenDoubleQuote:
case Lexer::Token::TokenNot:
case Lexer::Token::TokenAnd:
case Lexer::Token::TokenOr:
case Lexer::Token::TokenXor:
case Lexer::Token::TokenShl:
case Lexer::Token::TokenShr:
case Lexer::Token::TokenSal:
case Lexer::Token::TokenFalse:
case Lexer::Token::TokenTrue:
case Lexer::Token::TokenFloat:
case Lexer::Token::TokenString:
case Lexer::Token::TokenHex:
case Lexer::Token::TokenInt:
case Lexer::Token::TokenIf:
case Lexer::Token::TokenThen:
case Lexer::Token::TokenElseIf:
case Lexer::Token::TokenElse:
case Lexer::Token::TokenEndIf:
case Lexer::Token::TokenSelect:
case Lexer::Token::TokenCase:
case Lexer::Token::TokenDefault:
case Lexer::Token::TokenGoto:
case Lexer::Token::TokenGosub:
case Lexer::Token::TokenReturn:
case Lexer::Token::TokenFunction:
case Lexer::Token::TokenEnd:
case Lexer::Token::TokenStop:
case Lexer::Token::TokenFor:
case Lexer::Token::TokenTo:
case Lexer::Token::TokenNext:
case Lexer::Token::TokenWhile:
case Lexer::Token::TokenWend:
case Lexer::Token::TokenRepeat:
case Lexer::Token::TokenUntil:
case Lexer::Token::TokenForever:
case Lexer::Token::TokenExit:
case Lexer::Token::TokenAbs:
case Lexer::Token::TokenSign:
case Lexer::Token::TokenCos:
case Lexer::Token::TokenSin:
case Lexer::Token::TokenTan:
case Lexer::Token::TokenACos:
case Lexer::Token::TokenASin:
case Lexer::Token::TokenATan:
case Lexer::Token::TokenATan2:
case Lexer::Token::TokenLog:
case Lexer::Token::TokenLog10:
case Lexer::Token::TokenCeil:
case Lexer::Token::TokenFloor:
case Lexer::Token::TokenMod:
case Lexer::Token::TokenPi:
case Lexer::Token::TokenExp:
case Lexer::Token::TokenSqr:
case Lexer::Token::TokenConst:
case Lexer::Token::TokenGlobal:
case Lexer::Token::TokenLocal:
case Lexer::Token::TokenInclude:
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::TokenComment:
std::cout << "Comment(" << tkn.second << ")" << ' ';
break;
case Lexer::Token::TokenUnknown:
default:
std::cout << "Unknown(" << tkn.second << ") ";
break;
}
}
return true;
}