aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ast_node.hpp36
-rw-r--r--include/lexer.hpp (renamed from include/lexer/lexer.hpp)5
-rw-r--r--include/parser.hpp (renamed from include/parser/parser.hpp)5
-rw-r--r--include/parser/ast_node.hpp70
-rw-r--r--include/parser/node_type.hpp10
-rw-r--r--include/scope.hpp (renamed from include/semantic/scope.hpp)0
-rw-r--r--include/semantic_analyzer.hpp (renamed from include/semantic/semantic_analyzer.hpp)0
-rw-r--r--include/symbol.hpp (renamed from include/semantic/symbol.hpp)0
-rw-r--r--include/symbol_table.hpp (renamed from include/semantic/symbol_table.hpp)0
-rw-r--r--include/symbol_type.hpp (renamed from include/semantic/symbol_type.hpp)0
-rw-r--r--include/token.hpp (renamed from include/lexer/token.hpp)5
-rw-r--r--include/token_type.hpp (renamed from include/lexer/token_type.hpp)5
-rw-r--r--include/type.hpp11
13 files changed, 51 insertions, 96 deletions
diff --git a/include/ast_node.hpp b/include/ast_node.hpp
new file mode 100644
index 0000000..caffb35
--- /dev/null
+++ b/include/ast_node.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "node_type.hpp"
+#include "type.hpp"
+
+#include <string>
+#include <vector>
+#include <memory>
+
+class ASTNode {
+public:
+ int line;
+ int column;
+
+ virtual ~ASTNode() = default;
+};
+
+class ProgramNode : ASTNode {
+public:
+ std::vector<ASTNode> function_declarations;
+
+ explicit ProgramNode(std::vector<ASTNode> f) : function_declarations(f) { }
+};
+
+class FunctionDeclNode : ASTNode {
+ Type type;
+ std::vector<ParameterNode> parameters;
+ std::vector<ASTNode> body;
+
+ FunctionDeclNode(std::string t,std::vector<ASTNode> p, std::vector<ASTNode> b) : type(t), parameters(p), body(b) { }
+};
+
+class ParameterNode : ASTNode {
+ std::string name;
+ std::string type;
+};
diff --git a/include/lexer/lexer.hpp b/include/lexer.hpp
index 2c165b6..2ef9700 100644
--- a/include/lexer/lexer.hpp
+++ b/include/lexer.hpp
@@ -1,5 +1,4 @@
-#ifndef LEXER_H
-#define LEXER_H
+#pragma once
#include "token.hpp"
@@ -23,5 +22,3 @@ private:
void skipWhitespace();
void skipComment();
};
-
-#endif
diff --git a/include/parser/parser.hpp b/include/parser.hpp
index 438b8fe..f986ce2 100644
--- a/include/parser/parser.hpp
+++ b/include/parser.hpp
@@ -1,5 +1,4 @@
-#ifndef PARSER_H
-#define PARSER_H
+#pragma once
#include "lexer/token.hpp"
#include "parser/ast_node.hpp"
@@ -27,5 +26,3 @@ private:
bool isAtEnd();
void error(std::string s);
};
-
-#endif
diff --git a/include/parser/ast_node.hpp b/include/parser/ast_node.hpp
deleted file mode 100644
index 6539cf6..0000000
--- a/include/parser/ast_node.hpp
+++ /dev/null
@@ -1,70 +0,0 @@
-#ifndef AST_NODE_H
-#define AST_NODE_H
-
-#include "node_type.hpp"
-
-#include <string>
-#include <vector>
-#include <memory>
-
-class ASTNode {
-public:
- int line;
- int column;
-
- virtual ~ASTNode() = default;
-};
-
-class Program : public ASTNode {
-public:
- std::vector<std::unique_ptr<ASTNode>> declarations;
-};
-
-class Declaration : public ASTNode {
-public:
- std::string type;
- std::string var_name;
- std::unique_ptr<ASTNode> value;
-
- Declaration(std::string type, std::string var_name, std::unique_ptr<ASTNode> value = nullptr) : type(type), var_name(var_name), value(std::move(value)) {}
-};
-
-class Assignment : public ASTNode {
-public:
- std::string variable_name;
- std::unique_ptr<ASTNode> value;
-
- Assignment(std::string var, std::unique_ptr<ASTNode> val) : variable_name(var), value(std::move(val)) {}
-};
-
-class NumberLiteral : public ASTNode {
-public:
- double value;
-
- NumberLiteral(double val) : value(val) {}
-};
-
-class StringLiteral : public ASTNode {
-public:
- std::string value;
-
- StringLiteral(std::string val) : value(val) {}
-};
-
-class Identifier : public ASTNode {
-public:
- std::string name;
-
- Identifier(std::string name) : name(name) {}
-};
-
-class BinaryOp : public ASTNode {
-public:
- std::unique_ptr<ASTNode> left;
- std::string value;
- std::unique_ptr<ASTNode> right;
-
- BinaryOp(std::unique_ptr<ASTNode> left, std::string value, std::unique_ptr<ASTNode> right) : left(std::move(left)), value(std::move(value)), right(std::move(right)) {}
-};
-
-#endif
diff --git a/include/parser/node_type.hpp b/include/parser/node_type.hpp
deleted file mode 100644
index 1766b19..0000000
--- a/include/parser/node_type.hpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef NODE_TYPE_H
-#define NODE_TYPE_H
-
-enum class NodeType {
- PROGRAM,
- VARIABLE_DECLARATION,
- ASSIGNMENT,
-};
-
-#endif
diff --git a/include/semantic/scope.hpp b/include/scope.hpp
index ff20542..ff20542 100644
--- a/include/semantic/scope.hpp
+++ b/include/scope.hpp
diff --git a/include/semantic/semantic_analyzer.hpp b/include/semantic_analyzer.hpp
index 0d56599..0d56599 100644
--- a/include/semantic/semantic_analyzer.hpp
+++ b/include/semantic_analyzer.hpp
diff --git a/include/semantic/symbol.hpp b/include/symbol.hpp
index 4bee45d..4bee45d 100644
--- a/include/semantic/symbol.hpp
+++ b/include/symbol.hpp
diff --git a/include/semantic/symbol_table.hpp b/include/symbol_table.hpp
index b2b8270..b2b8270 100644
--- a/include/semantic/symbol_table.hpp
+++ b/include/symbol_table.hpp
diff --git a/include/semantic/symbol_type.hpp b/include/symbol_type.hpp
index a792c09..a792c09 100644
--- a/include/semantic/symbol_type.hpp
+++ b/include/symbol_type.hpp
diff --git a/include/lexer/token.hpp b/include/token.hpp
index 86a41f6..d85ba94 100644
--- a/include/lexer/token.hpp
+++ b/include/token.hpp
@@ -1,5 +1,4 @@
-#ifndef TOKEN_H
-#define TOKEN_H
+#pragma once
#include "token_type.hpp"
@@ -13,5 +12,3 @@ struct Token {
Token(TokenType t, const std::string& val, int line, int col) : type{t}, value{val}, line{line}, column{col} {};
};
-
-#endif
diff --git a/include/lexer/token_type.hpp b/include/token_type.hpp
index f83c6d6..d123aaa 100644
--- a/include/lexer/token_type.hpp
+++ b/include/token_type.hpp
@@ -1,5 +1,4 @@
-#ifndef TOKEN_TYPE_H
-#define TOKEN_TYPE_H
+#pragma once
enum class TokenType {
INT,
@@ -21,5 +20,3 @@ enum class TokenType {
INVALID
};
-
-#endif
diff --git a/include/type.hpp b/include/type.hpp
new file mode 100644
index 0000000..c46ff34
--- /dev/null
+++ b/include/type.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+enum struct Type {
+ INT,
+ CHAR,
+ BOOL,
+ STRING,
+ FLOAT,
+ DOUBLE,
+ VOID,
+};