Skip to content

Commit 66555c5

Browse files
committed
All downhill from here
0 parents  commit 66555c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3926
-0
lines changed

.gitignore

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
CMakeLists.txt.user
2+
CMakeCache.txt
3+
CMakeFiles
4+
CMakeScripts
5+
Testing
6+
Makefile
7+
cmake_install.cmake
8+
install_manifest.txt
9+
compile_commands.json
10+
CTestTestfile.cmake
11+
_deps
12+
13+
.idea/**/workspace.xml
14+
.idea/**/tasks.xml
15+
.idea/**/usage.statistics.xml
16+
.idea/**/dictionaries
17+
.idea/**/shelf
18+
19+
# AWS User-specific
20+
.idea/**/aws.xml
21+
22+
# Generated files
23+
.idea/**/contentModel.xml
24+
25+
# Sensitive or high-churn files
26+
.idea/**/dataSources/
27+
.idea/**/dataSources.ids
28+
.idea/**/dataSources.local.xml
29+
.idea/**/sqlDataSources.xml
30+
.idea/**/dynamic.xml
31+
.idea/**/uiDesigner.xml
32+
.idea/**/dbnavigator.xml
33+
34+
# Gradle
35+
.idea/**/gradle.xml
36+
.idea/**/libraries
37+
38+
# Gradle and Maven with auto-import
39+
# When using Gradle or Maven with auto-import, you should exclude module files,
40+
# since they will be recreated, and may cause churn. Uncomment if using
41+
# auto-import.
42+
# .idea/artifacts
43+
# .idea/compiler.xml
44+
# .idea/jarRepositories.xml
45+
# .idea/modules.xml
46+
# .idea/*.iml
47+
# .idea/modules
48+
# *.iml
49+
# *.ipr
50+
51+
# CMake
52+
cmake-build-*/
53+
54+
# Mongo Explorer plugin
55+
.idea/**/mongoSettings.xml
56+
57+
# File-based project format
58+
*.iws
59+
60+
# IntelliJ
61+
out/
62+
63+
# mpeltonen/sbt-idea plugin
64+
.idea_modules/
65+
66+
# JIRA plugin
67+
atlassian-ide-plugin.xml
68+
69+
# Cursive Clojure plugin
70+
.idea/replstate.xml
71+
72+
# SonarLint plugin
73+
.idea/sonarlint/
74+
75+
# Crashlytics plugin (for Android Studio and IntelliJ)
76+
com_crashlytics_export_strings.xml
77+
crashlytics.properties
78+
crashlytics-build.properties
79+
fabric.properties
80+
81+
# Editor-based Rest Client
82+
.idea/httpRequests
83+
84+
# Android studio 3.1+ serialized cache file
85+
.idea/caches/build_file_checksums.ser
86+
87+
**/.DS_Store

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/at.iml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/discord.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vscode/c_cpp_properties.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"macFrameworkPath": [],
10+
"compilerPath": "/usr/local/bin/gcc-11",
11+
"cStandard": "gnu17",
12+
"cppStandard": "gnu++17",
13+
"intelliSenseMode": "macos-gcc-x64"
14+
}
15+
],
16+
"version": 4
17+
}

CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
project(kt2cpp)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
# Set flags for release mode
6+
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
7+
8+
set(
9+
SRC_FILES
10+
include/Lexer.h src/Lexer.cpp include/Token.h src/Token.cpp src/Position.cpp include/Error.h src/Error.cpp include/Parser.h include/Nodes/Node.h
11+
src/Node.cpp include/Nodes/NumberNode.h src/NumberNode.cpp include/ParseResult.h src/ParseResult.cpp src/Parser.cpp include/Nodes/UnaryOpNode.h src/UnaryOpNode.cpp
12+
include/Nodes/BinaryOpNode.h src/BinaryOpNode.cpp include/Nodes/VarAssignNode.h src/VarAssignNode.cpp src/VarAccessNode.cpp include/Nodes/VarAccessNode.h
13+
include/Nodes/IfNode.h src/IfNode.cpp include/Nodes/ForNode.h src/ForNode.cpp include/Nodes/FuncDefNode.h src/FuncDefNode.cpp include/Nodes/CallNode.h src/CallNode.cpp
14+
include/Nodes/WhileNode.h src/WhileNode.cpp include/Nodes/StringNode.h src/StringNode.cpp include/Nodes/ListNode.h src/ListNode.cpp include/Nodes/ReturnNode.h
15+
src/ReturnNode.cpp include/Nodes/BreakNode.h include/Nodes/ContinueNode.h src/ContinueNode.cpp src/BreakNode.cpp include/Nodes/PackageNode.h
16+
src/PackageNode.cpp include/Nodes/ClassNode.h src/ClassNode.cpp include/Nodes/IndexNode.h src/IndexNode.cpp include/Nodes/ImportNode.h src/ImportNode.cpp
17+
include/Nodes/MapNode.h src/MapNode.cpp include/Position.h include/Global.h include/Nodes/VarDeclNode.h src/VarDeclNode.cpp include/Nodes/ArgNode.h src/ArgNode.cpp
18+
include/Nodes/DataclassNode.h src/DataclassNode.cpp include/Transpiler.h src/Transpiler.cpp include/Nodes/TypeNode.h src/TypeNode.cpp
19+
)
20+
21+
22+
include_directories(include)
23+
24+
add_executable(kt2cpp main.cpp ${SRC_FILES})

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kt2cpp

include/Error.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Created by Aadi and Michael on 7/24/22.
3+
//
4+
5+
#ifndef AT_ERROR_H
6+
#define AT_ERROR_H
7+
8+
#include <vector>
9+
#include <sstream>
10+
#include <Position.h>
11+
#include "Global.h"
12+
#include "Token.h"
13+
14+
class Error {
15+
public:
16+
Position* posStart, * posEnd;
17+
string name, message;
18+
19+
Error(Position* posStart, Position* posEnd, string name, string message);
20+
Error(Token* tok, string name, string message);
21+
22+
[[nodiscard]] virtual string toString();
23+
24+
[[nodiscard]] string addArrows(const string& text) const;
25+
};
26+
27+
#endif //AT_ERROR_H

include/Global.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Created by richard may clarkson on 12/01/2023.
3+
//
4+
5+
#ifndef AT_GLOBAL_H
6+
#define AT_GLOBAL_H
7+
8+
9+
10+
#endif //AT_GLOBAL_H

include/Lexer.h

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// Created by Aadi and Michael on 7/23/22.
3+
//
4+
5+
#ifndef AT_LEXER_H
6+
#define AT_LEXER_H
7+
8+
#include <string>
9+
#include <vector>
10+
#include <unordered_map>
11+
#include <Token.h>
12+
#include <Error.h>
13+
14+
using namespace std;
15+
16+
class Lexer {
17+
private:
18+
string* txt;
19+
char currentChar;
20+
Position* pos;
21+
unordered_map<string, TokenType> keywords = {
22+
{"class", CLASS},
23+
{"data", DATA},
24+
{"in", IN},
25+
{"return", RETURN},
26+
{"continue", CONTINUE},
27+
{"break", BREAK},
28+
{"package", PACKAGE},
29+
{"fun", FUN},
30+
{"as", AS},
31+
{"do", DO},
32+
{"for", FOR},
33+
{"while", WHILE},
34+
{"var", VAR},
35+
{"val", VAR},
36+
{"else", ELSE},
37+
{"if", IF},
38+
{"xor", BIT_XOR},
39+
{"and", BIT_AND},
40+
{"or", BIT_OR},
41+
{"import", IMPORT},
42+
{"step", STEP},
43+
{"downTo", DOWNTO}
44+
};
45+
46+
unordered_map<char, char> escapeChars = {
47+
{'n', '\n'},
48+
{'t', '\t'},
49+
{'r', '\r'},
50+
{'b', '\b'},
51+
{'f', '\f'},
52+
{'a', '\a'},
53+
{'\\', '\\'},
54+
{'"', '"'},
55+
{'\'', '\''},
56+
{'e', '\033'},
57+
};
58+
public:
59+
Error* error = nullptr;
60+
61+
Lexer(string* text, string* fileName);
62+
63+
vector<Token*> tokenize();
64+
65+
void advance();
66+
void skipComment();
67+
68+
Token* makeNumber();
69+
Token* makeString();
70+
Token* makeIdentifier();
71+
Token* makeLessThan();
72+
Token* makeGreaterThan();
73+
Token* makeQuestionMark();
74+
Token* makeEquals();
75+
Token* makeArrow();
76+
Token* makePlus();
77+
Token* makeModulo();
78+
Token* makeMultiply();
79+
Token* makeDivide();
80+
Token* makeOr();
81+
Token* makeAnd();
82+
Token* makeDot();
83+
Token* makeNot();
84+
};
85+
86+
#endif //AT_LEXER_H

include/Nodes/ArgNode.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Created by richard may clarkson on 13/01/2023.
3+
//
4+
5+
#ifndef AT_ARGNODE_H
6+
#define AT_ARGNODE_H
7+
8+
#include "Node.h"
9+
#include "Token.h"
10+
#include "Global.h"
11+
#include "TypeNode.h"
12+
13+
class ArgNode : public Node {
14+
public:
15+
Token* idTok;
16+
TypeNode* typeNode;
17+
Node* defaultValue;
18+
19+
ArgNode();
20+
ArgNode(Token* idTok, TypeNode* typeTok, Node* value);
21+
22+
[[nodiscard]] string toString() const override;
23+
};
24+
25+
#endif //AT_ARGNODE_H

include/Nodes/BinaryOpNode.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Created by Aadi and Michael on 7/25/22.
3+
//
4+
5+
#ifndef AT_BINARYOPNODE_H
6+
#define AT_BINARYOPNODE_H
7+
8+
#include <Nodes/Node.h>
9+
#include <Token.h>
10+
11+
class BinaryOpNode : public Node {
12+
public:
13+
Node* left, * right;
14+
Token* opTok;
15+
16+
BinaryOpNode(Token* opTok, Node* left, Node* right);
17+
18+
[[nodiscard]] string toString() const override;
19+
};
20+
21+
#endif //AT_BINARYOPNODE_H

include/Nodes/BreakNode.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Created by Aadi and Michael on 8/1/22.
3+
//
4+
5+
#ifndef AT_BREAKNODE_H
6+
#define AT_BREAKNODE_H
7+
8+
#include <Nodes/Node.h>
9+
#include "Global.h"
10+
11+
class BreakNode : public Node {
12+
public:
13+
BreakNode(Position* posStart, Position* posEnd);
14+
15+
[[nodiscard]] string toString() const override;
16+
};
17+
18+
#endif //AT_BREAKNODE_H

include/Nodes/CallNode.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Created by Aadi and Michael on 7/27/22.
3+
//
4+
5+
#ifndef AT_CALLNODE_H
6+
#define AT_CALLNODE_H
7+
8+
#include <vector>
9+
#include <Token.h>
10+
#include <Nodes/Node.h>
11+
12+
class CallNode : public Node {
13+
public:
14+
Node* toCall;
15+
vector<Node*> args;
16+
17+
CallNode(Node* toCall, vector<Node*> args);
18+
19+
string toString() const override;
20+
};
21+
22+
#endif //AT_CALLNODE_H

0 commit comments

Comments
 (0)