aboutsummaryrefslogtreecommitdiff
path: root/lib/Parser/ParserExpression.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 06:54:32 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 06:54:32 +0000
commit74b6d06711afd3efbbc47436f1491900994313f3 (patch)
treeb9050214b147cd2b1b54fd27e75d669bf6146e48 /lib/Parser/ParserExpression.cc
parent39661855c0816ac248be437704c76f58359cb5f0 (diff)
feat(classes): allocate objects with NEW and rebind named class variables
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser/ParserExpression.cc')
-rw-r--r--lib/Parser/ParserExpression.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Parser/ParserExpression.cc b/lib/Parser/ParserExpression.cc
index f4e074e..96132aa 100644
--- a/lib/Parser/ParserExpression.cc
+++ b/lib/Parser/ParserExpression.cc
@@ -168,6 +168,9 @@ std::unique_ptr<ExprAST> Parser::ParsePrimary() {
std::unique_ptr<ExprAST> Parser::ParsePrimaryImpl() {
switch (CurTok) {
+ case tok_new:
+ fprintf(stderr, "error: NEW is only allowed on the right of an assignment at line %d\n", Lex.getLine());
+ return nullptr;
case tok_identifier: return ParseIdentifierExpr();
case tok_number_int: return ParseNumberExpr();
case tok_number_real: return ParseNumberExpr();
@@ -299,3 +302,19 @@ std::optional<std::vector<std::unique_ptr<ExprAST>>> Parser::ParseExprList(char
getNextToken();
return Elems;
}
+
+std::unique_ptr<ExprAST> Parser::ParseAssignmentRHS() {
+ if (CurTok != tok_new) return ParseExpression();
+ int Line = Lex.getLine();
+ getNextToken();
+ std::string ClassName = ParseTypeName(false);
+ if (ClassName.empty()) return nullptr;
+ std::vector<std::unique_ptr<ExprAST>> Args;
+ if (CurTok == '(') {
+ getNextToken();
+ auto Parsed = ParseExprList(')', true);
+ if (!Parsed) return nullptr;
+ Args = std::move(*Parsed);
+ }
+ return std::make_unique<NewExprAST>(ClassName, std::move(Args), Line);
+}