feat(furc/parser): add while statement

This commit is contained in:
2026-08-08 00:07:38 +02:00
parent 1db13b4e10
commit 7ebc27cab9
3 changed files with 26 additions and 1 deletions
+8
View File
@@ -53,6 +53,7 @@ public:
Compound, Compound,
If, If,
While,
Return, Return,
}; };
public: public:
@@ -77,6 +78,13 @@ struct if_stmt_node final : public stmt_node {
stmt_node* elseBranch = nullptr; stmt_node* elseBranch = nullptr;
}; };
struct while_stmt_node final : public stmt_node {
stmt_type_e stmt_type() const override { return While; }
expr_node* cond = nullptr;
stmt_node* body = nullptr;
};
struct return_stmt_node final : public stmt_node { struct return_stmt_node final : public stmt_node {
stmt_type_e stmt_type() const override { return Return; } stmt_type_e stmt_type() const override { return Return; }
+9
View File
@@ -46,6 +46,15 @@ stmt_node* parser::parse_stmt() {
} }
return m_arena->allocate<if_stmt_node>(std::move(node)); return m_arena->allocate<if_stmt_node>(std::move(node));
} }
case token::While: {
m_lexer.next_token();
eat_token(token::LParen);
while_stmt_node node;
node.cond = parse_expr();
eat_token(token::RParen);
node.body = parse_stmt();
return m_arena->allocate<while_stmt_node>(std::move(node));
}
default: break; default: break;
} }
+9 -1
View File
@@ -5,7 +5,15 @@
int main(void) { int main(void) {
furlang::arena arena; furlang::arena arena;
furc::lexer lexer = { "<AK>", "func main(argc: u64) -> s32 { x: s32 = 10 + 67 - 6 * 7; }" }; std::string_view content = R"(
func main(argc: u64) -> s32 {
x: s32 = 1 + 2 * 3;
if (x == 9) return 1;
else return 0;
}
)";
furc::lexer lexer = { "<AK>", content };
furc::parser parser = { std::move(lexer), arena }; furc::parser parser = { std::move(lexer), arena };
auto program = parser.parse(); auto program = parser.parse();