diff options
Diffstat (limited to 'boot/parser.yy')
| -rw-r--r-- | boot/parser.yy | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/boot/parser.yy b/boot/parser.yy index 9f610ee..c34c905 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -153,14 +153,16 @@ along with GCC; see the file COPYING3. If not see %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 <elna::boot::field_initializer> field_initializer; +%type <std::unique_ptr<elna::boot::field_initializer>> field_initializer; %type <std::vector<elna::boot::field_initializer>> field_initializers; %type <std::vector<elna::boot::conditional_statements *>> elsif_then_statements elsif_do_statements; %type <std::vector<elna::boot::statement *> *> else_statements; %type <elna::boot::cast_expression *> cast_expression; -%type <elna::boot::identifier_definition> identifier_definition; +%type <std::unique_ptr<elna::boot::identifier>> identifier; +%type <std::unique_ptr<elna::boot::identifier_definition>> identifier_definition; %type <std::vector<elna::boot::identifier_definition>> identifier_definitions; -%type <std::vector<std::string>> identifiers import_declaration; +%type <std::vector<std::string>> import_declaration; +%type <std::vector<elna::boot::identifier>> identifiers; %type <std::vector<elna::boot::import_declaration *>> import_declarations import_part; %% program: @@ -176,16 +178,18 @@ procedure_body: statement_part: /* no statements */ {} | "begin" statements { $$ = $2; } +identifier: + IDENTIFIER { $$ = std::make_unique<boot::identifier>($1, boot::make_position(@1)); } identifier_definition: - IDENTIFIER "*" { $$ = boot::identifier_definition{ $1, true }; } - | IDENTIFIER { $$ = boot::identifier_definition{ $1, false }; } + IDENTIFIER "*" { $$ = std::make_unique<boot::identifier_definition>($1, boot::make_position(@1), true); } + | IDENTIFIER { $$ = std::make_unique<boot::identifier_definition>($1, boot::make_position(@1), false); } identifier_definitions: identifier_definition "," identifier_definitions { $$ = $3; - $$.emplace($$.cbegin(), $1); + $$.emplace($$.cbegin(), std::move(*$1)); } - | identifier_definition { $$.emplace_back($1); } + | identifier_definition { $$.emplace_back(std::move(*$1)); } return_declaration: /* proper procedure */ {} | ":" "!" { $$ = boot::procedure_type_expression::return_t(std::monostate{}); } @@ -195,11 +199,11 @@ procedure_heading: "(" optional_fields ")" return_declaration procedure_declaration: "proc" identifier_definition procedure_heading procedure_body { - $$ = new boot::procedure_declaration(boot::make_position(@$), $2, $3, std::move(*$4)); + $$ = new boot::procedure_declaration(boot::make_position(@$), std::move(*$2), $3, std::move(*$4)); } | "proc" identifier_definition procedure_heading "extern" { - $$ = new boot::procedure_declaration(boot::make_position(@$), $2, $3); + $$ = new boot::procedure_declaration(boot::make_position(@$), std::move(*$2), $3); } procedure_part: /* no procedure declarations */ {} @@ -247,7 +251,8 @@ literal: traits_expression: TRAIT "(" type_expressions ")" { - $$ = new boot::traits_expression(boot::make_position(@$), $1, $3); + $$ = new boot::traits_expression(boot::make_position(@$), + boot::identifier($1, boot::make_position(@1)), $3); } simple_expression: literal { $$ = $1; } @@ -256,9 +261,9 @@ simple_expression: | cast_expression { $$ = $1; } | call_expression { $$ = $1; } | "(" expression ")" { $$ = $2; } - | IDENTIFIER "{" field_initializers "}" + | identifier "{" field_initializers "}" { - $$ = new boot::record_constructor_expression(boot::make_position(@$), $1, $3); + $$ = new boot::record_constructor_expression(boot::make_position(@$), std::move(*$1), $3); } | "[" INTEGER "]" type_expression "{" expressions "}" { @@ -365,8 +370,8 @@ type_expressions: designator_expression: simple_expression "[" expression "]" { $$ = new boot::array_access_expression(boot::make_position(@$), $1, $3); } - | simple_expression "." IDENTIFIER - { $$ = new boot::field_access_expression(boot::make_position(@$), $1, $3); } + | simple_expression "." identifier + { $$ = new boot::field_access_expression(boot::make_position(@$), $1, std::move(*$3)); } | simple_expression "^" { $$ = new boot::dereference_expression(boot::make_position(@$), $1); } | IDENTIFIER @@ -426,14 +431,14 @@ optional_fields: required_fields { $$ = $1; } | /* no fields */ {} field_initializer: - IDENTIFIER ":" expression { $$.name = $1; $$.value = $3; } + identifier ":" expression { $$ = std::make_unique<boot::field_initializer>(std::move(*$1), $3); } field_initializers: field_initializer "," field_initializers { $$ = $3; - $$.emplace($$.cbegin(), $1); + $$.emplace($$.cbegin(), std::move(*$1)); } - | field_initializer { $$.push_back($1); } + | field_initializer { $$.push_back(std::move(*$1)); } type_expression: "[" INTEGER "]" type_expression { @@ -447,9 +452,9 @@ type_expression: { $$ = new boot::record_type_expression(boot::make_position(@$), $2); } - | "record" "(" IDENTIFIER ")" optional_fields "end" + | "record" "(" identifier ")" optional_fields "end" { - $$ = new boot::record_type_expression(boot::make_position(@$), $5, $3); + $$ = new boot::record_type_expression(boot::make_position(@$), $5, std::move(*$3)); } | "proc" procedure_heading { @@ -464,12 +469,12 @@ type_expression: $$ = new boot::named_expression(boot::make_position(@$), $1); } identifiers: - IDENTIFIER "," identifiers + identifier "," identifiers { $$ = $3; - $$.emplace($$.cbegin(), $1); + $$.emplace($$.cbegin(), std::move(*$1)); } - | IDENTIFIER { $$.emplace_back($1); } + | identifier { $$.emplace_back(std::move(*$1)); } variable_declaration: identifier_definitions ":" type_expression { @@ -498,7 +503,7 @@ variable_part: | "var" variable_declarations { $$ = $2; } constant_declaration: identifier_definition ":=" expression { - $$ = new boot::constant_declaration(boot::make_position(@$), $1, $3); + $$ = new boot::constant_declaration(boot::make_position(@$), std::move(*$1), $3); } constant_declarations: constant_declaration constant_declarations @@ -532,7 +537,7 @@ import_part: | "import" import_declarations { $$ = $2; } type_declaration: identifier_definition "=" type_expression { - $$ = new boot::type_declaration(boot::make_position(@$), $1, $3); + $$ = new boot::type_declaration(boot::make_position(@$), std::move(*$1), $3); } type_declarations: type_declaration type_declarations |
