feat(furc/parser): add return statement

This commit is contained in:
2026-08-08 00:07:23 +02:00
parent 84c6795ff8
commit 1db13b4e10
2 changed files with 16 additions and 0 deletions
+7
View File
@@ -53,6 +53,7 @@ public:
Compound, Compound,
If, If,
Return,
}; };
public: public:
category_e category() const override { return ast_node_cat::Statement; } category_e category() const override { return ast_node_cat::Statement; }
@@ -76,6 +77,12 @@ struct if_stmt_node final : public stmt_node {
stmt_node* elseBranch = nullptr; stmt_node* elseBranch = nullptr;
}; };
struct return_stmt_node final : public stmt_node {
stmt_type_e stmt_type() const override { return Return; }
expr_node* value = nullptr;
};
class decl_node : public stmt_node { class decl_node : public stmt_node {
public: public:
enum decl_type_e { enum decl_type_e {
+9
View File
@@ -24,6 +24,15 @@ ast parser::parse() {
stmt_node* parser::parse_stmt() { stmt_node* parser::parse_stmt() {
switch (m_lexer.peek_token().type) { switch (m_lexer.peek_token().type) {
case token::LBrace: return m_arena->allocate<comp_stmt_node>(parse_comp()); case token::LBrace: return m_arena->allocate<comp_stmt_node>(parse_comp());
case token::Return: {
m_lexer.next_token();
return_stmt_node node;
if (m_lexer.peek_token().type != token::Semicolon) {
node.value = parse_expr();
}
eat_token(token::Semicolon);
return m_arena->allocate<return_stmt_node>(std::move(node));
}
case token::If: { case token::If: {
m_lexer.next_token(); m_lexer.next_token();
eat_token(token::LParen); eat_token(token::LParen);