aboutsummaryrefslogtreecommitdiff
path: root/boot/parser.yy
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-13 18:14:45 +0200
committerEugen Wissner <belka@caraus.de>2026-07-13 18:14:45 +0200
commit500c0676b3f6cd5a2297987d5b0dc7ccf34a28d9 (patch)
treea394c73de9273489e6045f3d252714b5ac69b17c /boot/parser.yy
parent97741a01323021ccec8b0b60c6f8318c88ac373a (diff)
downloadelna-500c0676b3f6cd5a2297987d5b0dc7ccf34a28d9.tar.gz
Make return statement part of the body and not a statement
Diffstat (limited to 'boot/parser.yy')
-rw-r--r--boot/parser.yy62
1 files changed, 17 insertions, 45 deletions
diff --git a/boot/parser.yy b/boot/parser.yy
index aace9a1..f1bf915 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -131,16 +131,14 @@ along with GCC; see the file COPYING3. If not see
%type <elna::boot::type_expression *> type_expression;
%type <std::vector<elna::boot::type_expression *>> type_expressions;
%type <elna::boot::traits_expression *> traits_expression;
-%type <elna::boot::expression *> expression operand simple_expression;
+%type <elna::boot::expression *> expression operand simple_expression return_statement;
%type <elna::boot::unary_expression *> unary_expression;
%type <elna::boot::binary_expression *> binary_expression;
%type <std::vector<elna::boot::expression *>> expressions actual_parameter_list;
%type <elna::boot::designator_expression *> designator_expression;
%type <elna::boot::procedure_call*> call_expression;
-%type <elna::boot::return_statement *> return_statement;
%type <elna::boot::statement *> statement;
-%type <std::vector<elna::boot::statement *>> statements;
-%type <std::unique_ptr<std::vector<elna::boot::statement *>>> statement_part;
+%type <std::vector<elna::boot::statement *>> statements statement_part;
%type <elna::boot::procedure_declaration *> procedure_declaration;
%type <elna::boot::procedure_type_expression *> procedure_heading;
%type <elna::boot::procedure_type_expression::return_t> return_declaration;
@@ -159,49 +157,22 @@ along with GCC; see the file COPYING3. If not see
%type <std::vector<elna::boot::import_declaration *>> import_declarations import_part;
%%
program:
- import_part constant_part type_part variable_part procedure_part statement_part "end" "."
- {
- boot::unit *tree;
- if ($6)
- {
- tree = new boot::unit(boot::make_position(@1),
- std::move(*$6.release()));
- }
- else
- {
- tree = new boot::unit(boot::make_position(@1));
- }
- driver.tree.reset(tree);
-
- std::swap(driver.tree->imports, $1);
- std::swap(driver.tree->constants, $2);
- std::swap(driver.tree->types , $3);
- std::swap(driver.tree->variables, $4);
- std::swap(driver.tree->procedures, $5);
- }
-procedure_body: constant_part variable_part statement_part "end"
- {
- if ($3)
- {
- $$ = std::make_unique<boot::procedure_body>(std::move($1), std::move($2), std::move(*$3.release()));
- }
- else
- {
- $$ = std::make_unique<boot::procedure_body>(std::move($1), std::move($2));
- }
- }
-statement_part:
- /* no statements */ {}
- | "begin" statements { $$ = std::make_unique<std::vector<boot::statement *>>(std::move($2));; }
- | return_statement
+ import_part constant_part type_part variable_part procedure_part statement_part return_statement "end" "."
{
- $$ = std::make_unique<std::vector<boot::statement *>>(std::vector<boot::statement *>{ $1 });
+ boot::unit *tree = new boot::unit(boot::make_position(@1),
+ std::move($1), std::move($2), std::move($3), std::move($4), std::move($5),
+ std::move($6), $7);
+ driver.tree.reset(tree);
}
- | "begin" statements ";" return_statement
+procedure_body:
+ constant_part variable_part statement_part return_statement "end"
{
- $$ = std::make_unique<std::vector<boot::statement *>>(std::move($2));
- $$->push_back($4);
+ $$ = std::make_unique<boot::procedure_body>(std::move($1), std::move($2), std::move($3), $4);
}
+
+statement_part:
+ /* no statements */ {}
+ | "begin" statements { std::swap($$, $2); }
identifier_definition:
IDENTIFIER "*" { $$ = boot::identifier_definition{ $1, true }; }
| IDENTIFIER { $$ = boot::identifier_definition{ $1, false }; }
@@ -263,8 +234,9 @@ elsif_then_statements:
$$.emplace($$.begin(), branch);
}
| /* no branches */ {}
-return_statement: "return" expression
- { $$ = new boot::return_statement(boot::make_position(@1), $2); }
+return_statement:
+ "return" expression { $$ = $2; }
+ | /* no return statement */ { $$ = nullptr; }
literal:
INTEGER { $$ = new boot::literal<std::int32_t>(boot::make_position(@1), $1); }
| WORD { $$ = new boot::literal<std::uint32_t>(boot::make_position(@1), $1); }