diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-09-13 20:12:08 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-09-13 20:12:08 +0200 |
| commit | 38a24d57067b657cde572f92210c5719091c88ff (patch) | |
| tree | c608ea8fc81a0e8f8783299b8677e6a11216ca7f | |
| parent | a5d033df465ca8de8457926cc64aacf38c6ae848 (diff) | |
| download | elna-38a24d57067b657cde572f92210c5719091c88ff.tar.gz | |
Allow reordering sections
| -rw-r--r-- | boot/parser.yy | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/boot/parser.yy b/boot/parser.yy index 9c9e728..68af60e 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -132,7 +132,7 @@ along with GCC; see the file COPYING3. If not see %type <elna::boot::switch_case> switch_case; %type <std::vector<elna::boot::switch_case>> switch_cases; %type <elna::boot::variable_declaration *> variable_declaration; -%type <std::vector<elna::boot::variable_declaration *>> variable_declarations variable_part; +%type <std::vector<elna::boot::variable_declaration *>> variable_declarations; %type <elna::boot::type_expression *> type_expression; %type <std::vector<elna::boot::type_expression *>> type_expressions; %type <elna::boot::expression *> expression operand simple_expression procedure_return unary_expression; @@ -145,9 +145,9 @@ along with GCC; see the file COPYING3. If not see %type <elna::boot::procedure_declaration *> procedure_declaration; %type <std::unique_ptr<elna::boot::procedure_type_expression>> procedure_heading; %type <elna::boot::procedure_type_expression::return_t> return_declaration; -%type <std::vector<elna::boot::procedure_declaration *>> procedure_part; %type <std::unique_ptr<elna::boot::type_declaration>> type_declaration; -%type <std::vector<elna::boot::declaration *>> type_declarations type_part; +%type <std::vector<elna::boot::declaration *>> type_declarations; +%type <std::vector<elna::boot::declaration *>> module_declaration module_declarations; %type <std::unique_ptr<elna::boot::procedure_body>> procedure_body; %type <elna::boot::field_declaration> field_declaration; %type <std::vector<elna::boot::field_declaration>> field_declarations; @@ -167,40 +167,47 @@ along with GCC; see the file COPYING3. If not see %type <std::unique_ptr<elna::boot::array_type_expression>> array_type_expression; %% program: - import_part type_part variable_part procedure_part "end" "." + import_part module_declarations "end" "." { driver.finished = true; - std::vector<boot::declaration *> declarations = $2; - std::vector<boot::variable_declaration *> variables = $3; - declarations.insert(declarations.end(), - std::make_move_iterator(variables.begin()), std::make_move_iterator(variables.end())); - std::vector<boot::procedure_declaration *> appendix = $4; - declarations.insert(declarations.end(), - std::make_move_iterator(appendix.begin()), std::make_move_iterator(appendix.end())); - - boot::unit *tree = new boot::unit(boot::make_position(@$), $1, std::move(declarations)); + boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2); driver.tree.reset(tree); } - | import_part type_part variable_part procedure_part + | import_part module_declarations "program" "(" optional_identifiers ")" procedure_body "end" "." { driver.finished = true; - std::vector<boot::declaration *> declarations = $2; - std::vector<boot::variable_declaration *> variables = $3; - declarations.insert(declarations.end(), - std::make_move_iterator(variables.begin()), std::make_move_iterator(variables.end())); - std::vector<boot::procedure_declaration *> appendix = $4; - declarations.insert(declarations.end(), - std::make_move_iterator(appendix.begin()), std::make_move_iterator(appendix.end())); - boot::unit *tree = new boot::unit(boot::make_position(@$), $1, std::move(declarations), - std::move($7), boot::make_position(@5), std::move(*$9)); + boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, + std::move($5), boot::make_position(@3), std::move(*$7)); driver.tree.reset(tree); } +module_declaration: + "type" type_declarations { $$ = $2; } + | "var" variable_declarations + { + std::vector<boot::variable_declaration *> variables = $2; + + $$.insert($$.end(), variables.begin(), variables.end()); + } + | procedure_declaration { $$.emplace_back($1); } +module_declarations: + %empty {} + | module_declaration module_declarations + { + std::vector<boot::declaration *> appendix = $2; + + $$ = $1; + $$.insert($$.end(), appendix.begin(), appendix.end()); + } procedure_body: - variable_part statement_part procedure_return - { $$ = std::make_unique<boot::procedure_body>($1, $2, $3); } + "var" variable_declarations statement_part procedure_return + { $$ = std::make_unique<boot::procedure_body>($2, $3, $4); } + | statement_part procedure_return + { + $$ = std::make_unique<boot::procedure_body>(std::vector<boot::variable_declaration *>(), $1, $2); + } statement_part: %empty {} @@ -256,13 +263,6 @@ procedure_declaration: $$ = new boot::procedure_declaration(boot::make_position(@$), std::move(*$2), $4.release()); $$->parameters = $3; } -procedure_part: - %empty {} - | procedure_declaration procedure_part - { - $$ = $2; - $$.emplace($$.cbegin(), $1); - } call_expression: designator_expression actual_parameter_list { $$ = std::make_unique<boot::procedure_call>(boot::make_position(@$), $1, $2); @@ -696,9 +696,6 @@ variable_declarations: $$ = $2; $$.insert(std::cbegin($$), $1); } -variable_part: - %empty {} - | "var" variable_declarations { $$ = $2; } import_declaration: IDENTIFIER "." import_declaration { @@ -737,9 +734,6 @@ type_declarations: $$.insert($$.cbegin(), $1.release()); } | %empty {} -type_part: - %empty {} - | "type" type_declarations { $$ = $2; } actual_parameter_list: "(" optional_expressions ")" { $$ = $2; } %% |
