feat: for 循环 + range (for i in start..end)
- lexer: TOK_FOR, TOK_IN, TOK_DOT_DOT + 修复数字中 .. 解析
- parser: for-in-range → desugar to {let mut, while, assign}
- 零 sema/codegen 改动,复用现有机制
- 新增 2 个集成测试 (10_for_range.l, 11_for_step2.l)
- mem2reg: LLVM 22 C API 不导出,标注已知限制
基于 Codex 分析报告 §6 P0 #3。
This commit is contained in:
+4
-2
@@ -45,7 +45,7 @@ static Token lex_number(Lexer* l) {
|
||||
int start = l->pos;
|
||||
TokenKind kind = TOK_INT_LIT;
|
||||
while (isdigit(peek(l))) advance(l);
|
||||
if (peek(l) == '.') {
|
||||
if (peek(l) == '.' && peek_next(l) != '.') {
|
||||
kind = TOK_FLOAT_LIT; advance(l);
|
||||
while (isdigit(peek(l))) advance(l);
|
||||
}
|
||||
@@ -57,7 +57,8 @@ static TokenKind check_keyword(const Token* tok) {
|
||||
KW("fn", TOK_FN); KW("let", TOK_LET);
|
||||
KW("mut", TOK_MUT);
|
||||
KW("if", TOK_IF); KW("else", TOK_ELSE);
|
||||
KW("while", TOK_WHILE); KW("return", TOK_RETURN);
|
||||
KW("while", TOK_WHILE); KW("for", TOK_FOR); KW("in", TOK_IN);
|
||||
KW("return", TOK_RETURN);
|
||||
KW("i64", TOK_I64); KW("f64", TOK_F64);
|
||||
KW("bool", TOK_BOOL); KW("str", TOK_STR);
|
||||
KW("void", TOK_VOID);
|
||||
@@ -124,6 +125,7 @@ Token* lex(Arena* a, const char* source, const char* filename,
|
||||
else if (c == '>') { tokens[idx++] = make_token(&l, TOK_GT, l.pos, 1); advance(&l); }
|
||||
else if (c == '&' && peek_next(&l) == '&') { tokens[idx++] = make_token(&l, TOK_AND_AND, l.pos, 2); advance(&l); advance(&l); }
|
||||
else if (c == '|' && peek_next(&l) == '|') { tokens[idx++] = make_token(&l, TOK_PIPE_PIPE, l.pos, 2); advance(&l); advance(&l); }
|
||||
else if (c == '.' && peek_next(&l) == '.') { tokens[idx++] = make_token(&l, TOK_DOT_DOT, l.pos, 2); advance(&l); advance(&l); }
|
||||
else if (c == '(') { tokens[idx++] = make_token(&l, TOK_LPAREN, l.pos, 1); advance(&l); }
|
||||
else if (c == ')') { tokens[idx++] = make_token(&l, TOK_RPAREN, l.pos, 1); advance(&l); }
|
||||
else if (c == '{') { tokens[idx++] = make_token(&l, TOK_LBRACE, l.pos, 1); advance(&l); }
|
||||
|
||||
Reference in New Issue
Block a user