Comments, var access, start on objects

This commit is contained in:
2025-10-26 19:16:35 +11:00
parent c73142178a
commit 191410d174
4 changed files with 30 additions and 15 deletions

View File

@@ -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();
}

View File

@@ -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<std::string> 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<ASTFunctionCall>(fnNameStr, ASTCodeBlock(args).nodes));
break;
}

View File

@@ -84,18 +84,6 @@ Executor::Executor(ASTCodeBlock in, bool isInitCall, std::map<std::string, ASTVa
std::cout << "Expected value after = sign" << std::endl;
exit(1);
}
} else if (id == "==") {
} else if (id == "!=") {
} else if (id == ">") {
} 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<std::string, ASTVa
for (auto &callArgNode : callArgNodes) {
if (std::holds_alternative<std::shared_ptr<ASTValue>>(callArgNode)) {
callArgs.push_back(*std::get<std::shared_ptr<ASTValue>>(callArgNode));
} else if (std::holds_alternative<std::shared_ptr<ASTIdentifier>>(callArgNode)) {
if (variables.find(std::get<std::shared_ptr<ASTIdentifier>>(callArgNode)->name) != variables.end()) {
callArgs.push_back(variables[std::get<std::shared_ptr<ASTIdentifier>>(callArgNode)->name]);
}
}
}
if (fnName == "import") {
// work on importing modules later

View File

@@ -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<Object> children;
};
class Executor {
private:
std::map<std::string, ASTFunction> functions;