From 313736addd6d6c1ec4957c69b63a10e997aba9ff Mon Sep 17 00:00:00 2001 From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com> Date: Tue, 12 Aug 2025 23:56:12 +0100 Subject: [PATCH] Added basic vector --- LXC/LXC.cpp | 2 ++ parser/src/Parser.cpp | 53 +++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/LXC/LXC.cpp b/LXC/LXC.cpp index 61ac09f..3817f3d 100644 --- a/LXC/LXC.cpp +++ b/LXC/LXC.cpp @@ -73,5 +73,7 @@ int main(int argc, char** argv) Util::Log("Function AST", functionsAST.Result()); } + functionsAST.Result().~vector(); + return 0; } diff --git a/parser/src/Parser.cpp b/parser/src/Parser.cpp index 1c77059..b77e3b1 100644 --- a/parser/src/Parser.cpp +++ b/parser/src/Parser.cpp @@ -210,7 +210,7 @@ namespace PashaBibko::LXC::Parser return Util::FunctionFail(); // <- TODO: Make an actual error // Checks for a default value for the variable // - const Lexer::Token* varAssign = ctx.Peek(); + const Lexer::Token* varAssign = ctx.Advance(); if (varAssign == nullptr) return Internal::CreateNode(varNameStr); @@ -254,36 +254,31 @@ namespace PashaBibko::LXC::Parser if (paramsStart == nullptr ) return Util::FunctionFail(); // <- TODO: Make an actual error - // Parses the parameters of the function // - if (paramsStart->type == Lexer::Token::Identifier && paramsStart->Str() == "void") - { /* No parameters/arguments for the function */} - - // Loops over the parameters/arguments of the function declaration // - else + while (ctx.At()->type != Lexer::Token::CloseParen) { - while (ctx.At()->type != Lexer::Token::CloseParen) - { - // Checks for parameter pattern: identifier, identifier // - if (!ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::Colon, Lexer::Token::Identifier })) - return Util::FunctionFail(); // <- TODO: Make an actual error - - const Lexer::Token* paramType = ctx.At(); - const Lexer::Token* paramName = ctx.Advance(2); // Skips over seperating colon - - currentFunction.funcParams.emplace_back(paramType->Str(), paramName->Str()); - - // Expects a comma or close bracket for the next token // - const Lexer::Token* end = ctx.Advance(); - if (end == nullptr) - return Util::FunctionFail(); // <- TODO: Make an actual error - - if (end->type == Lexer::Token::Comma || end->type == Lexer::Token::CloseParen) - continue; - + // Checks for parameter pattern: identifier, identifier // + if (!ctx.Expect(std::array{ Lexer::Token::Identifier, Lexer::Token::Colon, Lexer::Token::Identifier })) return Util::FunctionFail(); // <- TODO: Make an actual error - } + + const Lexer::Token* paramType = ctx.At(); + const Lexer::Token* paramName = ctx.Advance(2); // Skips over seperating colon + + currentFunction.funcParams.emplace_back(paramType->Str(), paramName->Str()); + + // Expects a comma or close bracket for the next token // + const Lexer::Token* end = ctx.Advance(); + if (end == nullptr) + return Util::FunctionFail(); // <- TODO: Make an actual error + + if (end->type == Lexer::Token::Comma || end->type == Lexer::Token::CloseParen) + continue; + + return Util::FunctionFail(); // <- TODO: Make an actual error } + // Adcances over close paren and open brace // + ctx.Advance(2); + // Parses the function body // const Lexer::Token* current = ctx.At(); while (current != nullptr) @@ -301,9 +296,7 @@ namespace PashaBibko::LXC::Parser return Util::FunctionFail(node.Error()); // Fowards the error currentFunction.contents.emplace_back(std::move(node.Result())); - - // Advances to the next token // - current = ctx.Advance(); + current = ctx.At(); } return Util::FunctionFail(); // <- TODO: Make an actual error