From 1db13b4e1049f5ea902f1faedbfa4659597bdc35 Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Sat, 8 Aug 2026 00:07:23 +0200 Subject: [PATCH] feat(furc/parser): add return statement --- furc/include/furc/front/ast.hpp | 7 +++++++ furc/src/front/parser.cpp | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/furc/include/furc/front/ast.hpp b/furc/include/furc/front/ast.hpp index b13c39f..dd9c1f9 100644 --- a/furc/include/furc/front/ast.hpp +++ b/furc/include/furc/front/ast.hpp @@ -53,6 +53,7 @@ public: Compound, If, + Return, }; public: 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; }; +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 { public: enum decl_type_e { diff --git a/furc/src/front/parser.cpp b/furc/src/front/parser.cpp index 0756037..fb50b87 100644 --- a/furc/src/front/parser.cpp +++ b/furc/src/front/parser.cpp @@ -24,6 +24,15 @@ ast parser::parse() { stmt_node* parser::parse_stmt() { switch (m_lexer.peek_token().type) { case token::LBrace: return m_arena->allocate(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(std::move(node)); + } case token::If: { m_lexer.next_token(); eat_token(token::LParen);