Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The Programming Language Research Group at the University of Tenten Academy is a group of
faculty, postdocs, and students interested in programming languages and related areas.
We meet weekly to discuss research papers and work in progress. We also host the Programming
Languages Seminar, which brings in speakers from other institutions.

We are part of the Computer Science Department at the University of Tenten Academy.

By using the Programming Language Research Lab, it is not allowed to use the following:
- Use the Programming Language Research Lab for any illegal purpose.
- Use the Programming Language Research Lab for any malicious purpose.
- Use the Programming Language Research Lab for any commercial purpose.
- Use the Programming Language Research Lab for any profit purpose.

By using the Programming Language Research Lab, it is allowed to use the following:
- Use the Programming Language Research Lab for any educational purpose.
- Use the Programming Language Research Lab for any research purpose.
- Use the Programming Language Research Lab for any non-commercial purpose.
- Use the Programming Language Research Lab for any personal purpose.
- Use the Programming Language Research Lab for any non-profit purpose.
- Use the Programming Language Research Lab for any purpose that is not listed in the "not allowed" list.
- Use the Programming Language Research Lab for data science and computer science research.
9 changes: 0 additions & 9 deletions build/CMakeCache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,6 @@ cosmolangarchitecture_IS_TOP_LEVEL:STATIC=ON
//Value Computed by CMake
cosmolangarchitecture_SOURCE_DIR:STATIC=/mnt/g/CosmolangProgrammingLanguageProjects/CosmolangArchitecture

//Value Computed by CMake
hydrogen_BINARY_DIR:STATIC=/mnt/g/CosmolangProgrammingLanguageProjects/CosmolangArchitecture/build

//Value Computed by CMake
hydrogen_IS_TOP_LEVEL:STATIC=ON

//Value Computed by CMake
hydrogen_SOURCE_DIR:STATIC=/mnt/g/CosmolangProgrammingLanguageProjects/CosmolangArchitecture


########################
# INTERNAL cache entries
Expand Down
120 changes: 60 additions & 60 deletions build/CMakeFiles/CMakeOutput.log

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/CMakeFiles/cosarch.dir/compiler_depend.internal
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,5 @@ CMakeFiles/cosarch.dir/src/main.cpp.o
/usr/include/c++/11/bits/stl_vector.h
/usr/include/c++/11/bits/stl_bvector.h
/usr/include/c++/11/bits/vector.tcc
/mnt/g/CosmolangProgrammingLanguageProjects/CosmolangArchitecture/src/tokenization.hpp

5 changes: 4 additions & 1 deletion build/CMakeFiles/cosarch.dir/compiler_depend.make
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ CMakeFiles/cosarch.dir/src/main.cpp.o: ../src/main.cpp \
/usr/include/c++/11/bits/stl_uninitialized.h \
/usr/include/c++/11/bits/stl_vector.h \
/usr/include/c++/11/bits/stl_bvector.h \
/usr/include/c++/11/bits/vector.tcc
/usr/include/c++/11/bits/vector.tcc \
../src/tokenization.hpp


../src/tokenization.hpp:

/usr/include/c++/11/bits/stl_bvector.h:

/usr/include/c++/11/bits/stl_uninitialized.h:
Expand Down
Binary file modified build/CMakeFiles/cosarch.dir/src/main.cpp.o
Binary file not shown.
3 changes: 2 additions & 1 deletion build/CMakeFiles/cosarch.dir/src/main.cpp.o.d
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,5 @@ CMakeFiles/cosarch.dir/src/main.cpp.o: \
/usr/include/c++/11/vector /usr/include/c++/11/bits/stl_uninitialized.h \
/usr/include/c++/11/bits/stl_vector.h \
/usr/include/c++/11/bits/stl_bvector.h \
/usr/include/c++/11/bits/vector.tcc
/usr/include/c++/11/bits/vector.tcc \
/mnt/g/CosmolangProgrammingLanguageProjects/CosmolangArchitecture/src/./tokenization.hpp
Binary file modified build/cosarch
Binary file not shown.
Binary file removed data/out
Binary file not shown.
5 changes: 0 additions & 5 deletions data/out.asm

This file was deleted.

Binary file removed data/out.o
Binary file not shown.
6 changes: 6 additions & 0 deletions push_github.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
git init
git add *
git commit -m "The first step to the future of the full programming language. The CosArch is a Programming Language Research Lab."
git branch -M main
git remote add origin https://github.com/DevKiDMediaCreation/cosmolangarchitecture-CosArch.git
git push -u origin main
8 changes: 6 additions & 2 deletions shell/+$~#adoin32vrcmasc.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

mkdir -p build
mkdir -p build
cmake -S . -B build/
cmake --build build/
./build/cosarch ./test.cos
# echo $?
# echo $?

echo Running Program
../data/out
echo $?
10 changes: 10 additions & 0 deletions shell/23508123_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

rm -rf build
mkdir -p build
./build/cosarch ./test.cos

echo Running Program
./data/out
echo $?
# End of snippet from shell/%2B%24%EF%80%AA~%23adoin32vrcmasc.sh
130 changes: 57 additions & 73 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,78 +1,23 @@
//
// Create by DevKiD 15.09.2023
//
#include <iostream>
#include <fstream>
#include <sstream>
#include <optional>
#include <vector>

enum class TokenType {
_return,
int_lit,
semi,
};

struct Token {
TokenType type;
std::optional<std::string> value {};
};

std::vector<Token> tokenize(const std::string& str) {
std::vector<Token> tokens;

std::string buf;
for (int i = 0; i < str.length(); i++) {
char c = str.at(i);
if (std::isalpha(c)) {
buf.push_back(c);
i++;
while (std::isalnum(str.at(i))) {
buf.push_back(str.at(i));
i++;
}
i--;

if (buf == "return") {
tokens.push_back({.type = TokenType::_return});
buf.clear();
continue;
} else {
std::cerr << "Syntax error." << std::endl;
exit(EXIT_FAILURE);
}
} else if(std::isdigit(c)) {
buf.push_back(c);
i++;
while(std::isdigit(str.at(i))) {
buf.push_back(str.at(i));
i++;
}
i--;
tokens.push_back({.type = TokenType::int_lit, .value = buf});
buf.clear();
}
else if (c == ';') {
tokens.push_back({.type = TokenType::semi});
}
else if(std::isspace(c)) {
continue;
}
else {
std::cerr << "Syntax error." << std::endl;
exit(EXIT_FAILURE);
}
}
#include "./tokenization.hpp"

return tokens;
}

// Intergrade Cosmolang Linker and Cosmolang Assembler ICL and ICA
std::string tokens_to_asm(const std::vector<Token>& tokens) {
// Integrate Cosmolang Linker and Cosmolang Assembler ICL and ICA
std::string tokens_to_asm(const std::vector<Token> &tokens) {
std::stringstream output;
output << "global _start\n_start:\n";
for(int i = 0; i <tokens.size(); i++) {
const Token& token = tokens.at(i);
if(token.type == TokenType::_return) {
if(i + 1 < tokens.size() && tokens.at(i + 1).type == TokenType::int_lit) {
if(i + 2 < tokens.size() && tokens.at(i + 2).type == TokenType::semi) {
for (int i = 0; i < tokens.size(); i++) {
const Token &token = tokens.at(i);
if (token.type == TokenType::exit) {
if (i + 1 < tokens.size() && tokens.at(i + 1).type == TokenType::int_lit) {
if (i + 2 < tokens.size() && tokens.at(i + 2).type == TokenType::semi) {
output << " mov rax, 60\n";
output << " mov rdi, " << tokens.at(i + 1).value.value() << "\n";
output << " syscall\n";
Expand All @@ -84,8 +29,9 @@ std::string tokens_to_asm(const std::vector<Token>& tokens) {
return output.str();
}

int main(int argc, char* argv[]) {
if(argc != 2) { // < 2
int main(int argc, char *argv[]) {
std::cout << "Running Cosarch v0.0.1. Cosmolang Architecture Programming Language Research Labs" << std::endl;
if (argc != 2) { // < 2
std::cerr << "Incorrect usage. Correct usage is..." << std::endl;
std::cerr << "cosarch <input.cos>" << std::endl;
return EXIT_FAILURE;
Expand All @@ -98,27 +44,65 @@ int main(int argc, char* argv[]) {
contents_stream << input.rdbuf();
contents = contents_stream.str();

if(contents == "") {
if (contents.empty()) {
std::cerr << "File is empty." << std::endl;
return EXIT_FAILURE;
}
}

system("mkdir -p ../data");
system("rm -fr ../data && mkdir -p ../data");

/**if (argv[2] != nullptr) {
std::string command = "rm -fr " + std::string(argv[2]) + " && mkdir -p " + std::string(argv[2]);
system(command.c_str());
} else {
system("rm -fr ../data && mkdir -p ../data");
}*/

std::vector<Token> tokens = tokenize(contents);
Tokenizer tokenizer(std::move(contents));
std::vector<Token> tokens = tokenizer.tokenize();
{
/**if (argv[2] != nullptr) {
std::fstream file(std::string(argv[2]) + "/out.asm", std::ios::out);
file << tokens_to_asm(tokens);
} else {
std::fstream file("../data/out.asm", std::ios::out);
file << tokens_to_asm(tokens);
}*/
std::fstream file("../data/out.asm", std::ios::out);
file << tokens_to_asm(tokens);
}

system("nasm -f elf64 ../data/out.asm -o ../data/out.o && ld ../data/out.o -o ../data/out");

// For later
/**if(argv[3] == "--debug") {
std::cout << tokens_to_asm(tokens) << std::endl;
}*/

/**if (argv[2] != nullptr) {
std::string command =
"nasm -f elf64 " + std::string(argv[2]) + " /out.asm -o " + std::string(argv[2]) + "/out.o && ld " +
std::string(argv[2]) + "/out.o -o " + std::string(argv[2]) + "/out";
system(command.c_str());
} else {
system("nasm -f elf64 ../data/out.asm -o ../data/out.o && ld ../data/out.o -o ../data/out");
}*/

/**if(argv[2] == "-r") {
system("../data/out && echo $?");
}*/ // Add a -r run option to run the program after compiling

std::cout << "Compiling successfully." << std::endl;
std::cout << "Compiling successfully. File build: " << argv[1] << std::endl;

/**if (argv[3] == "-r") {
if (argv[2] == nullptr) {
system("../data/out && echo $?");
} else {
}
}*/

return EXIT_SUCCESS;
}
}

// 28:51
78 changes: 78 additions & 0 deletions src/tokenization.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#pragma once

#include <string>
#include <vector>


enum class TokenType {
_return, exit, int_lit, semi
};

struct Token {
TokenType type;
std::optional<std::string> value{};
};

class Tokenizer {
public:
inline explicit Tokenizer(std::string src) : m_src(std::move(src)) {

}

inline std::vector<Token> tokenize() {
std::vector<Token> tokens;
std::string buf;
while (peak().has_value()) {
if (std::isalpha(peak().value())) {
buf.push_back(consume());
while (peak().has_value() && std::isalnum(peak().value())) {
buf.push_back(consume());
}
if (buf == "exit") {
tokens.push_back({.type = TokenType::exit});
buf.clear();
continue;
} else {
std::cerr << "Syntax error. This error msg is very helpfully." << std::endl;
exit(EXIT_FAILURE);
}
} else if (std::isdigit(peak().value())) {
buf.push_back(consume());
while (peak().has_value() && std::isdigit(peak().value())) {
buf.push_back(consume());
}
tokens.push_back({.type = TokenType::int_lit, .value = buf});
buf.clear();
continue;
} else if (peak().value() == ';') {
consume();
tokens.push_back({.type = TokenType::semi});
continue;
} else if (std::isspace(peak().value())) {
consume();
continue;
} else {
std::cerr << "Syntax error. This error msg is very helpfully." << std::endl;
exit(EXIT_FAILURE);
}
}
std::cout << "Tokenization complete." << std::endl;
m_index = 0;
return tokens;
}

private:
[[nodiscard]] std::optional<char> peak(int ahead = 1) const {
if (m_index + ahead > m_src.length()) {
return {};
}
return m_src.at(m_index);
}

char consume() {
return m_src.at(m_index++);
}

const std::string m_src;
int m_index = 0;
};
2 changes: 1 addition & 1 deletion test.cos
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return 256;
exit 256;