From 191410d174ceae04fe621f553323ca38ef31aa14 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sun, 26 Oct 2025 19:16:35 +1100 Subject: [PATCH] Comments, var access, start on objects --- src/lexer/lexer.cpp | 4 ++++ src/parser/parser.cpp | 18 +++++++++++++++--- src/runner/runner.cpp | 17 +++++------------ src/runner/runner.h | 6 ++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/lexer/lexer.cpp b/src/lexer/lexer.cpp index ab6fa98..cd91ff2 100644 --- a/src/lexer/lexer.cpp +++ b/src/lexer/lexer.cpp @@ -60,6 +60,10 @@ Lexer::Lexer(std::string in) : file(std::move(in)) { if (!buf.empty()) content.push_back(buf); if (c.value() != ' ') content.emplace_back(1, c.value()); buf.clear(); + } else if (c.value() == '/' && peek(0).has_value() && peek(0).value() == '/') { + while (c.has_value() && c.value() != '\n') { + c = consume(); + } } else { buf += c.value(); } diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 8616c4d..fb8ec70 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -240,16 +240,28 @@ void ASTCodeBlock::parseBlock() { std::cout << "Reached end of file while parsing function call" << std::endl; exit(1); } - while (getTokenType() != TokenType::CloseParen) { + consume(); // Consume the opening '(' + int depth = 1; + while (depth > 0) { std::optional token = consume(); if (token.has_value()) { - args.push_back(token.value()); + if (token.value() == "(") { + depth++; + args.push_back(token.value()); + } else if (token.value() == ")") { + depth--; + if (depth == 0) { + break; + } + args.push_back(token.value()); + } else { + args.push_back(token.value()); + } } else { std::cout << "Reached end of file while parsing function call" << std::endl; exit(1); } } - consume(); nodes.emplace_back(std::make_shared(fnNameStr, ASTCodeBlock(args).nodes)); break; } diff --git a/src/runner/runner.cpp b/src/runner/runner.cpp index d98e2c8..890a49b 100644 --- a/src/runner/runner.cpp +++ b/src/runner/runner.cpp @@ -84,18 +84,6 @@ Executor::Executor(ASTCodeBlock in, bool isInitCall, std::map") { - - } else if (id == ">=") { - - } else if (id == "<") { - - } else if (id == "<=") { - } } else { std::cout << "Expected function or operator after identifier" << std::endl; @@ -112,7 +100,12 @@ Executor::Executor(ASTCodeBlock in, bool isInitCall, std::map>(callArgNode)) { callArgs.push_back(*std::get>(callArgNode)); + } else if (std::holds_alternative>(callArgNode)) { + if (variables.find(std::get>(callArgNode)->name) != variables.end()) { + callArgs.push_back(variables[std::get>(callArgNode)->name]); + } } + } if (fnName == "import") { // work on importing modules later diff --git a/src/runner/runner.h b/src/runner/runner.h index 2323bb9..ebe465b 100644 --- a/src/runner/runner.h +++ b/src/runner/runner.h @@ -13,6 +13,12 @@ * context of execution. The class implements mechanisms for traversing AST nodes * and consuming or peeking at individual nodes. */ + +class Object { + public: + std::vector children; +}; + class Executor { private: std::map functions;