diff options
Diffstat (limited to 'boot/parser.yy')
| -rw-r--r-- | boot/parser.yy | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/boot/parser.yy b/boot/parser.yy index 42840ff..6ada702 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -148,7 +148,7 @@ along with GCC; see the file COPYING3. If not see %type <std::vector<elna::boot::procedure_declaration *>> procedure_part; %type <elna::boot::type_declaration *> type_declaration; %type <std::vector<elna::boot::type_declaration *>> type_declarations type_part; -%type <std::unique_ptr<elna::boot::block>> block; +%type <std::unique_ptr<elna::boot::procedure_body>> procedure_body; %type <elna::boot::field_declaration> field_declaration; %type <std::vector<elna::boot::field_declaration>> optional_fields required_fields; %type <std::vector<elna::boot::conditional_statements *>> elsif_then_statements elsif_do_statements; @@ -162,32 +162,33 @@ along with GCC; see the file COPYING3. If not see program: import_part constant_part type_part variable_part procedure_part statement_part "end" "." { + boot::unit *tree; if ($6) { - boot::unit *tree = new boot::unit(boot::make_position(@1)); - tree->body = std::make_optional<std::vector<boot::statement *>>(std::move(*$6.release())); - - driver.tree.reset(tree); + tree = new boot::unit(boot::make_position(@1), + std::move(*$6.release())); } else { - driver.tree.reset(new boot::unit(boot::make_position(@1))); + 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); } -block: constant_part variable_part statement_part "end" +procedure_body: constant_part variable_part statement_part "end" { if ($3) { - $$ = std::make_unique<boot::block>(std::move($1), std::move($2), std::move(*$3.release())); + $$ = std::make_unique<boot::procedure_body>(std::move($1), std::move($2), std::move(*$3.release())); } else { - $$ = std::make_unique<boot::block>(std::move($1), std::move($2)); + $$ = std::make_unique<boot::procedure_body>(std::move($1), std::move($2)); } } statement_part: @@ -221,7 +222,7 @@ procedure_heading: "(" optional_fields ")" return_declaration $$ = new boot::procedure_type_expression(boot::make_position(@1), std::move($2), std::move($4)); } procedure_declaration: - "proc" identifier_definition procedure_heading block + "proc" identifier_definition procedure_heading procedure_body { $$ = new boot::procedure_declaration(boot::make_position(@1), std::move($2), $3, std::move(*$4)); @@ -251,7 +252,7 @@ elsif_do_statements: std::swap($5, $$); $$.emplace($$.begin(), branch); } - | {} + | /* no branches */ {} else_statements: "else" statements { $$ = new std::vector<boot::statement *>(std::move($2)); } | { $$ = nullptr; } @@ -262,7 +263,7 @@ elsif_then_statements: std::swap($5, $$); $$.emplace($$.begin(), branch); } - | {} + | /* no branches */ {} return_statement: "return" expression { $$ = new boot::return_statement(boot::make_position(@1), $2); } literal: |
