From 7ece0329332067f19e9301cfd27d679ec5ea7acd Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:13:07 +0000 Subject: [PATCH 01/22] Renamed output executable in main CMakeLists file! --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 236b8a6..31f4c89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.15) -project(Dragon C CXX) +project(Dragonfly C CXX) set(CMAKE_C_STANDARD 23) set(CMAKE_CXX_STANDARD 23) @@ -16,7 +16,7 @@ set(SOURCES src/main.cpp ) -add_executable(dragon src/main.cpp ${SOURCES}) +add_executable(dfc src/main.cpp ${SOURCES}) include(FetchContent) FetchContent_Declare( From 1d2388028299474135c74daf71ad33ca5bb4218a Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:14:51 +0000 Subject: [PATCH 02/22] Deleted parser_test.cpp (re-organising tests) --- tests/parser_test.cpp | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 tests/parser_test.cpp diff --git a/tests/parser_test.cpp b/tests/parser_test.cpp deleted file mode 100644 index 74a2bdc..0000000 --- a/tests/parser_test.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "dragon/lexer.h" -#include "dragon/token.h" -#include "dragon/parser.h" - -// Variable/Constant Declaration Node -// Variable/Constant Assignment Node -// While Loop Node -// For Loop Node -// If-Else Node -// Function Call Node \ No newline at end of file From a36c5a9027c98473c104a77c479a90e2778ffded Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:15:49 +0000 Subject: [PATCH 03/22] tests/CMakeLists.txt now tests all files in tests/parser/*.cpp --- tests/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4a1be1a..75ef744 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,6 @@ -add_executable(run_tests lexer_test.cpp parser_test.cpp semantics_test.cpp) +file(GLOB_RECURSE PARSER_TESTS "parser/*.cpp") + +add_executable(run_tests lexer_test.cpp ${PARSER_TESTS} semantics_test.cpp) target_link_libraries(run_tests gtest gtest_main pthread) target_include_directories(run_tests PRIVATE ../include) From b9a1a2b2d8a2d5435a2a3863ddd574ddc209261a Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:16:07 +0000 Subject: [PATCH 04/22] Added expression tests for parsing --- tests/parser/expressions.cpp | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/parser/expressions.cpp diff --git a/tests/parser/expressions.cpp b/tests/parser/expressions.cpp new file mode 100644 index 0000000..fa0ec28 --- /dev/null +++ b/tests/parser/expressions.cpp @@ -0,0 +1,38 @@ +#include + +#include "dragon/parser.h" +#include "dragon/token.h" +#include "dragon/lexer.h" + +struct ExpressionsTestParam { + std::string code; + std::string to_string_result; +}; + +class ExpressionsTests : public ::testing::TestWithParam {}; + +TEST_P(ExpressionsTests, HandlesExpressions) { + ExpressionsTestParam param = GetParam(); + + Parser parser(Lexer(param.code).lex()); + auto nodes = parser.parse_expression(); + + EXPECT_EQ(nodes->size(), 1) << "Expected 1 node, got " << nodes->size() << " nodes"; + EXPECT_EQ(nodes->to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes->to_string(); +} + +INSTANTIATE_TEST_SUITE_P( + ExpressionsVariations, + ExpressionsTests, + ::testing::Values( + ExpressionsTestParam{"5 + 5 - 10 * 100", "true"}, + ExpressionsTestParam{"10 / 4 + 3 * 4 - 9", "true"}, + ExpressionsTestParam{"(1 == 1) && true == false || !false", "true"}, + ExpressionsTestParam{"5 & 10 | 15 ^ 20", "true"}, + ExpressionsTestParam{"5 << 2 >> 2", "true"}, + ExpressionsTestParam{"5 < 10 > 15 <= 20 >= 25", "true"}, + ExpressionsTestParam{"5 == 5 != 10", "true"}, + ExpressionsTestParam{"5 && 10 || 15", "true"}, + ExpressionsTestParam{"5 ? 10 : 15", "true"} + ) +); From a3c2f486cbf5b0c54c780ccdebd89513c5bb32d3 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:16:18 +0000 Subject: [PATCH 05/22] Added variable declaration tests for parsing --- tests/parser/variable_declaration.cpp | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/parser/variable_declaration.cpp diff --git a/tests/parser/variable_declaration.cpp b/tests/parser/variable_declaration.cpp new file mode 100644 index 0000000..77c0aff --- /dev/null +++ b/tests/parser/variable_declaration.cpp @@ -0,0 +1,35 @@ +#include + +#include "dragon/parser.h" +#include "dragon/token.h" +#include "dragon/lexer.h" + +struct VariableTestParam { + std::string code; + std::string to_string_result; +}; + +class VariableDeclarationTests : public ::testing::TestWithParam {}; + +TEST_P(VariableDeclarationTests, HandlesVariableDeclarations) { + VariableTestParam param = GetParam(); + + Parser parser(Lexer(param.code).lex()); + auto nodes = parser.parse(); + + EXPECT_EQ(nodes.size(), 1) << "Expected 1 node, got " << nodes.size() << " nodes"; + EXPECT_EQ(nodes[0].to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes[0].to_string(); +} + +INSTANTIATE_TEST_SUITE_P( + VariableDeclarationVariations, + VariableDeclarationTests, + ::testing::Values( + VariableTestParam{"let x int = 5 + 5", "true"}, + VariableTestParam{"let x int", "true"}, + VariableTestParam{"let x = 5 + 5", "true"}, + VariableTestParam{"let mut x int = 5 + 5", "true"}, + VariableTestParam{"let mut x int", "true"}, + VariableTestParam{"let mut x = 5 + 5", "true"} + ) +); From b61c6a4275f3ba0e86527b210929cda165cc1dff Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:16:28 +0000 Subject: [PATCH 06/22] Added variable assignment tests for parsing --- tests/parser/variable_assignment.cpp | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/parser/variable_assignment.cpp diff --git a/tests/parser/variable_assignment.cpp b/tests/parser/variable_assignment.cpp new file mode 100644 index 0000000..fa3c31a --- /dev/null +++ b/tests/parser/variable_assignment.cpp @@ -0,0 +1,35 @@ +#include + +#include "dragon/lexer.h" +#include "dragon/token.h" +#include "dragon/parser.h" + +struct VariableTestParam { + std::string code; + std::string to_string_result; +}; + +class VariableAssignmentTests : public ::testing::TestWithParam {}; + +TEST_P(VariableAssignmentTests, HandlesVariableAssignments) { + VariableTestParam param = GetParam(); + + Parser parser(Lexer(param.code).lex()); + auto nodes = parser.parse(); + + EXPECT_EQ(nodes.size(), 1) << "Expected 1 node, got " << nodes.size() << " nodes"; + EXPECT_EQ(nodes[0].to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes[0].to_string(); +} + +INSTANTIATE_TEST_SUITE_P( + VariableAssignmentVariations, + VariableAssignmentTests, + ::testing::Values( + VariableTestParam{"x = 5 + 5", "true"}, + VariableTestParam{"x=10", "true"}, + VariableTestParam{"x += true", "true"}, + VariableTestParam{"x -= 10", "true"}, + VariableTestParam{"x *= 100 * 10", "true"}, + VariableTestParam{"x /= 5 + 5", "true"} + ) +); \ No newline at end of file From fb0dc698fe4ff67368c7402a9c15667cd088404d Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:16:38 +0000 Subject: [PATCH 07/22] Added for loop tests for parsing --- tests/parser/for_loop.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/parser/for_loop.cpp diff --git a/tests/parser/for_loop.cpp b/tests/parser/for_loop.cpp new file mode 100644 index 0000000..a03d320 --- /dev/null +++ b/tests/parser/for_loop.cpp @@ -0,0 +1,31 @@ +#include + +#include "dragon/parser.h" +#include "dragon/token.h" +#include "dragon/lexer.h" + +struct ForLoopTestParam { + std::string code; + std::string to_string_result; +}; + +class ForLoopTests : public ::testing::TestWithParam {}; + +TEST_P(ForLoopTests, HandlesForLoops) { + ForLoopTestParam param = GetParam(); + + Parser parser(Lexer(param.code).lex()); + auto nodes = parser.parse(); + + EXPECT_EQ(nodes[0].to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes[0].to_string(); +} + +INSTANTIATE_TEST_SUITE_P( + ForLoopVariations, + ForLoopTests, + ::testing::Values( + ForLoopTestParam{"for i in message { print(i) }", "ForLoopNode"}, + ForLoopTestParam{"for i in 0..10 { print(i) }", "ForLoopNode"}, + ForLoopTestParam{"for i in (10 + 20) {}", "ForLoopNode"} + ) +); \ No newline at end of file From 8ee0ea61ee77f1652eed10d878a294a19ccd54fc Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:16:46 +0000 Subject: [PATCH 08/22] Added function call tests for parsing --- tests/parser/function_call.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/parser/function_call.cpp diff --git a/tests/parser/function_call.cpp b/tests/parser/function_call.cpp new file mode 100644 index 0000000..844325a --- /dev/null +++ b/tests/parser/function_call.cpp @@ -0,0 +1,34 @@ +#include + +#include "dragon/parser.h" +#include "dragon/token.h" +#include "dragon/lexer.h" + +struct FunctionCallTestParam { + std::string code; + std::string to_string_result; +}; + +class FunctionCallTests : public ::testing::TestWithParam {}; + +TEST_P(FunctionCallTests, HandlesFunctionCalls) { + FunctionCallTestParam param = GetParam(); + + Parser parser(Lexer(param.code).lex()); + auto nodes = parser.parse(); + + EXPECT_EQ(nodes[0].to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes[0].to_string(); +} + +INSTANTIATE_TEST_SUITE_P( + FunctionCallVariations, + FunctionCallTests, + ::testing::Values( + FunctionCallTestParam{"print()", "FunctionCallNode"}, + FunctionCallTestParam{"print(5)", "FunctionCallNode"}, + FunctionCallTestParam{"print(5 + 5)", "FunctionCallNode"}, + FunctionCallTestParam{"print(5, 10)", "FunctionCallNode"}, + FunctionCallTestParam{"print(5, 10, 15)", "FunctionCallNode"}, + FunctionCallTestParam{"print(5 + 2, 10 * 30, print(100), 20)", "FunctionCallNode"} + ) +); \ No newline at end of file From d4955ac79f79508c1dbf9ff70f3540fff7012c88 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:16:53 +0000 Subject: [PATCH 09/22] Added if else tests for parsing --- tests/parser/if_else.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/parser/if_else.cpp diff --git a/tests/parser/if_else.cpp b/tests/parser/if_else.cpp new file mode 100644 index 0000000..b765152 --- /dev/null +++ b/tests/parser/if_else.cpp @@ -0,0 +1,32 @@ +#include + +#include "dragon/parser.h" +#include "dragon/token.h" +#include "dragon/lexer.h" + +struct IfElseTestParam { + std::string code; + std::string to_string_result; +}; + +class IfElseTests : public ::testing::TestWithParam {}; + +TEST_P(IfElseTests, HandlesIfElse) { + IfElseTestParam param = GetParam(); + + Parser parser(Lexer(param.code).lex()); + auto nodes = parser.parse(); + + EXPECT_EQ(nodes[0].to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes[0].to_string(); +} + +INSTANTIATE_TEST_SUITE_P( + IfElseVariations, + IfElseTests, + ::testing::Values( + IfElseTestParam{"if true { print(5) }", "IfElseNode"}, + IfElseTestParam{"if true==true { print(5) } else { print(10) }", "IfElseNode"}, + IfElseTestParam{"if true { print(5) } else if false { print(10) }", "IfElseNode"}, + IfElseTestParam{"if true { print(5) } else if false { print(10) } else { print(15) }", "IfElseNode"} + ) +); \ No newline at end of file From c96afe627e4e38b9a6b93f4d4f491952b953b82d Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:17:05 +0000 Subject: [PATCH 10/22] Added while loop tests for parsing --- tests/parser/while_loop.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/parser/while_loop.cpp diff --git a/tests/parser/while_loop.cpp b/tests/parser/while_loop.cpp new file mode 100644 index 0000000..b1c8d8a --- /dev/null +++ b/tests/parser/while_loop.cpp @@ -0,0 +1,32 @@ +#include + +#include "dragon/parser.h" +#include "dragon/token.h" +#include "dragon/lexer.h" + +struct WhileLoopTestParam { + std::string code; + std::string to_string_result; +}; + +class WhileLoopTests : public ::testing::TestWithParam {}; + +TEST_P(WhileLoopTests, HandlesWhileLoops) { + WhileLoopTestParam param = GetParam(); + + Parser parser(Lexer(param.code).lex()); + auto nodes = parser.parse(); + + EXPECT_EQ(nodes[0].to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes[0].to_string(); +} + +INSTANTIATE_TEST_SUITE_P( + WhileLoopVariations, + WhileLoopTests, + ::testing::Values( + WhileLoopTestParam{"while true { print(5) }", "WhileLoopNode"}, + WhileLoopTestParam{"while true == true { print(5) }", "WhileLoopNode"}, + WhileLoopTestParam{"while true { print(5) }", "WhileLoopNode"}, + WhileLoopTestParam{"while true { print(5) }", "WhileLoopNode"} + ) +); \ No newline at end of file From d37e6822f3aa3b7b81cbb00fe1291d751b3e3d43 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:17:29 +0000 Subject: [PATCH 11/22] Added some full program test files for more extensive future tests --- tests/test_programs/program1.df | 7 +++++++ tests/test_programs/program2.df | 33 +++++++++++++++++++++++++++++++++ tests/test_programs/program3.df | 0 3 files changed, 40 insertions(+) create mode 100644 tests/test_programs/program1.df create mode 100644 tests/test_programs/program2.df create mode 100644 tests/test_programs/program3.df diff --git a/tests/test_programs/program1.df b/tests/test_programs/program1.df new file mode 100644 index 0000000..e667d1e --- /dev/null +++ b/tests/test_programs/program1.df @@ -0,0 +1,7 @@ +let message = "Hello, world!" + +println("Let's spell \"Hello, world!\"") +for i in message { + println(i) +} +println(message) \ No newline at end of file diff --git a/tests/test_programs/program2.df b/tests/test_programs/program2.df new file mode 100644 index 0000000..6ea1cc6 --- /dev/null +++ b/tests/test_programs/program2.df @@ -0,0 +1,33 @@ +// This is a login system + +while true { + println("Username: ") + let mut username = input() + println("Password: ") + let mut password = input() + + if username == "admin" && password = "admin" { + println("Nice try HACKERMAN!") + } else if (username == "Will" || username == "Joe") { + println("Nuh uh... You're not allow!) + } else if username == "Remy" && password == "***" { + println("Welcome boss man!") + println(">> Try \"help\" for a list of commands!) + while true { + println(">> ") + let user_input = input() + if user_input == "help" { + println("Commands:") + println("help - shows this message") + println("logout - logs out of the system") + } else if user_input == "logout" { + println("Logging out! See ya next time...) + break + } + } + } else { + println("Nice try! Have another go...") + } +} + +println("System shutting down") \ No newline at end of file diff --git a/tests/test_programs/program3.df b/tests/test_programs/program3.df new file mode 100644 index 0000000..e69de29 From c2efa1861170eccc44e97839758bdcd6af655465 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:23:48 +0000 Subject: [PATCH 12/22] Added Node class (parent to all nodes) --- include/dragon/ast.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 include/dragon/ast.h diff --git a/include/dragon/ast.h b/include/dragon/ast.h new file mode 100644 index 0000000..c650859 --- /dev/null +++ b/include/dragon/ast.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include +#include +#include "token.h" + +class Node { +public: + virtual ~Node() = default; + virtual std::string to_string() const = 0; +}; From 6bebcc8605bfa990ab5edf45c048554a790bd48f Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:24:02 +0000 Subject: [PATCH 13/22] Added ExpressionNode and StatementNode --- include/dragon/ast.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/dragon/ast.h b/include/dragon/ast.h index c650859..37515cb 100644 --- a/include/dragon/ast.h +++ b/include/dragon/ast.h @@ -11,3 +11,30 @@ class Node { virtual ~Node() = default; virtual std::string to_string() const = 0; }; + +class ExpressionNode : public Node { +public: + Token op; + std::unique_ptr left; + std::unique_ptr right; + + ExpressionNode(Token token, std::unique_ptr left, std::unique_ptr right) + : op(std::move(token)), left(std::move(left)), right(std::move(right)) {} + + ~ExpressionNode() override = default; + + std::string to_string() const override { + return "ExpressionNode(op: " + op.to_string() + ")"; + } + + virtual std::variant eval() const = 0; + virtual size_t size() const = 0; +}; + +class StatementNode : public Node { +public: + virtual ~StatementNode() override = default; + virtual std::string to_string() const override = 0; +}; + + From 6b7a80195a2c7648eac883b524d858111ccbf5d2 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:25:37 +0000 Subject: [PATCH 14/22] Added skeleton nodes for for loops --- include/dragon/ast/for_loop_node.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 include/dragon/ast/for_loop_node.h diff --git a/include/dragon/ast/for_loop_node.h b/include/dragon/ast/for_loop_node.h new file mode 100644 index 0000000..594a5a6 --- /dev/null +++ b/include/dragon/ast/for_loop_node.h @@ -0,0 +1,5 @@ +#pragma once + +#include "../ast.h" + +class ForLoopNode : public StatementNode {}; \ No newline at end of file From ac0f9bdc52ef5465bb82e6adaa13fc6a953dc3e9 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:25:44 +0000 Subject: [PATCH 15/22] Added skeleton nodes for function calls --- include/dragon/ast/function_call_node.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 include/dragon/ast/function_call_node.h diff --git a/include/dragon/ast/function_call_node.h b/include/dragon/ast/function_call_node.h new file mode 100644 index 0000000..fe399af --- /dev/null +++ b/include/dragon/ast/function_call_node.h @@ -0,0 +1,5 @@ +#pragma once + +#include "../ast.h" + +class FunctionCallNode : public ExpressionNode {}; \ No newline at end of file From 867b580fa76ae12955b0d1a6c7a1d65cc0faceca Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:25:50 +0000 Subject: [PATCH 16/22] Added skeleton nodes for identifiers --- include/dragon/ast/identifier_node.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 include/dragon/ast/identifier_node.h diff --git a/include/dragon/ast/identifier_node.h b/include/dragon/ast/identifier_node.h new file mode 100644 index 0000000..72d3b54 --- /dev/null +++ b/include/dragon/ast/identifier_node.h @@ -0,0 +1,5 @@ +#pragma once + +#include "../ast.h" + +class IdentifierNode : public ExpressionNode {}; \ No newline at end of file From b29a37ec666699e4b1bc7875491c9ab636f0e244 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:26:00 +0000 Subject: [PATCH 17/22] Added skeleton nodes for if-else statements --- include/dragon/ast/if_else_node.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 include/dragon/ast/if_else_node.h diff --git a/include/dragon/ast/if_else_node.h b/include/dragon/ast/if_else_node.h new file mode 100644 index 0000000..bf6a3fb --- /dev/null +++ b/include/dragon/ast/if_else_node.h @@ -0,0 +1,5 @@ +#pragma once + +#include "../ast.h" + +class IfElseNode : public StatementNode {}; \ No newline at end of file From 626afc1da840566ece6942699750b6fb9b359f11 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:26:18 +0000 Subject: [PATCH 18/22] Added skeleton nodes for literal node --- include/dragon/ast/literal_node.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 include/dragon/ast/literal_node.h diff --git a/include/dragon/ast/literal_node.h b/include/dragon/ast/literal_node.h new file mode 100644 index 0000000..363c79f --- /dev/null +++ b/include/dragon/ast/literal_node.h @@ -0,0 +1,5 @@ +#pragma once + +#include "../ast.h" + +class LiteralNode : public ExpressionNode {}; \ No newline at end of file From c40ac013f7f7fc9bf116a590f4eecbf3c8a4b4c9 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:26:31 +0000 Subject: [PATCH 19/22] Added skeleton nodes for while loops --- include/dragon/ast/while_loop_node.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 include/dragon/ast/while_loop_node.h diff --git a/include/dragon/ast/while_loop_node.h b/include/dragon/ast/while_loop_node.h new file mode 100644 index 0000000..496ea71 --- /dev/null +++ b/include/dragon/ast/while_loop_node.h @@ -0,0 +1,5 @@ +#pragma once + +#include "../ast.h" + +class WhileLoopNode : public StatementNode {}; \ No newline at end of file From 3faf1f6f1d70f89a2b639f34d708e628da3b30e8 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:26:50 +0000 Subject: [PATCH 20/22] Added skeleton nodes for variable assignment --- include/dragon/ast/variable_assignment_node.h | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 include/dragon/ast/variable_assignment_node.h diff --git a/include/dragon/ast/variable_assignment_node.h b/include/dragon/ast/variable_assignment_node.h new file mode 100644 index 0000000..be7d79e --- /dev/null +++ b/include/dragon/ast/variable_assignment_node.h @@ -0,0 +1,5 @@ +#pragma once + +#include "../ast.h" + +class VariableAssignmentNode : public StatementNode {}; \ No newline at end of file From 6e313e04766dc473acf2120562fdfa5cd60fa36b Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:27:18 +0000 Subject: [PATCH 21/22] Added node skeleton for variable declarations --- include/dragon/ast/variable_declaration_node.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 include/dragon/ast/variable_declaration_node.h diff --git a/include/dragon/ast/variable_declaration_node.h b/include/dragon/ast/variable_declaration_node.h new file mode 100644 index 0000000..8a4f49d --- /dev/null +++ b/include/dragon/ast/variable_declaration_node.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include "../ast.h" + +class VariableDeclarationNode : public StatementNode { +}; \ No newline at end of file From e61f35bd3a68cccba83194d59459a8a675221ca0 Mon Sep 17 00:00:00 2001 From: hrszpuk <107559570+hrszpuk@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:27:46 +0000 Subject: [PATCH 22/22] Added attributes, constructor, destructor, and to_string to variable declaration node --- include/dragon/ast/variable_declaration_node.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/dragon/ast/variable_declaration_node.h b/include/dragon/ast/variable_declaration_node.h index 8a4f49d..6d58caf 100644 --- a/include/dragon/ast/variable_declaration_node.h +++ b/include/dragon/ast/variable_declaration_node.h @@ -4,4 +4,20 @@ #include "../ast.h" class VariableDeclarationNode : public StatementNode { +public: + Token identifier; + Token type; + std::unique_ptr value; + bool is_const; + + explicit VariableDeclarationNode(Token identifier, Token type, std::unique_ptr value, bool is_const) + : identifier(std::move(identifier)), type(std::move(type)), value(std::move(value)), is_const(is_const) {} + + ~VariableDeclarationNode() override = default; + + std::string to_string() const override { + return "VariableDeclarationNode(identifier: " + identifier.to_string() + + ", type: " + type.to_string() + + ", is_const: " + (is_const ? "true" : "false") + ")"; + } }; \ No newline at end of file