feat(furc/parser): add if statement

This commit is contained in:
2026-08-08 00:04:04 +02:00
parent 212b1e2384
commit 84c6795ff8
2 changed files with 24 additions and 0 deletions
+11
View File
@@ -52,6 +52,7 @@ public:
Expression,
Compound,
If,
};
public:
category_e category() const override { return ast_node_cat::Statement; }
@@ -65,6 +66,16 @@ struct comp_stmt_node final : public stmt_node {
std::vector<stmt_node*> stmts;
};
class expr_node;
struct if_stmt_node final : public stmt_node {
stmt_type_e stmt_type() const override { return If; }
expr_node* cond = nullptr;
stmt_node* thenBranch = nullptr;
stmt_node* elseBranch = nullptr;
};
class decl_node : public stmt_node {
public:
enum decl_type_e {
+13
View File
@@ -24,6 +24,19 @@ ast parser::parse() {
stmt_node* parser::parse_stmt() {
switch (m_lexer.peek_token().type) {
case token::LBrace: return m_arena->allocate<comp_stmt_node>(parse_comp());
case token::If: {
m_lexer.next_token();
eat_token(token::LParen);
if_stmt_node node;
node.cond = parse_expr();
eat_token(token::RParen);
node.thenBranch = parse_stmt();
if (m_lexer.peek_token().type == token::Else) {
m_lexer.next_token();
node.elseBranch = parse_stmt();
}
return m_arena->allocate<if_stmt_node>(std::move(node));
}
default: break;
}