aboutsummaryrefslogtreecommitdiff
path: root/lib/Parser
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 05:08:42 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 05:08:42 +0000
commita6b8afcfb61e1d321405fe8713beaec2aa6320a2 (patch)
treea621462bd6f858d1e78495e8c850a2e7321f4809 /lib/Parser
parent5c3d4d059ae70ea72b52e89940746d61c1d962db (diff)
feat(input): support array elements and member targets
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser')
-rw-r--r--lib/Parser/Parser.cc19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/Parser/Parser.cc b/lib/Parser/Parser.cc
index f2fcbc8..d4d04d2 100644
--- a/lib/Parser/Parser.cc
+++ b/lib/Parser/Parser.cc
@@ -116,14 +116,17 @@ std::unique_ptr<StmtAST> Parser::ParseStatementImpl() {
std::string Name = Lex.IdentifierStr;
int Line = Lex.getLine();
getNextToken();
- if (CurTok == '[' || CurTok == '.' || CurTok == '^') {
- // Consume the whole designator so it cannot replay as statements.
- std::vector<DesignatorAccess> Dummy;
- ParseDesignatorSuffix(Dummy);
- fprintf(stderr, "error: INPUT target must be a plain variable at line %d\n", Line);
- return nullptr;
- }
- return std::make_unique<InputStmtAST>(Name);
+ std::vector<DesignatorAccess> Accesses;
+ if (!ParseDesignatorSuffix(Accesses)) return nullptr;
+ std::unique_ptr<ExprAST> Target;
+ if (Accesses.empty())
+ Target = std::make_unique<VariableExprAST>(Name);
+ else if (Accesses.size() == 1 && Accesses[0].Kind == AccessKind::Index)
+ Target = std::make_unique<ArrayAccessExprAST>(Name, std::move(Accesses[0].Indices), Line);
+ else
+ Target = std::make_unique<DesignatorExprAST>(Name, std::move(Accesses), Line);
+ Target->setLine(Line);
+ return std::make_unique<InputStmtAST>(std::move(Target));
}
else if (CurTok == tok_output) {
getNextToken();