Allow expressions in designators

This commit is contained in:
2025-02-07 00:56:54 +01:00
parent 5e9b4259ca
commit 077de53c74
5 changed files with 51 additions and 40 deletions

View File

@ -328,6 +328,11 @@ unary:
$$ = new elna::boot::unary_expression(elna::boot::make_position(@1), $2,
elna::boot::unary_operator::negation);
}
| MINUS operand
{
$$ = new elna::boot::unary_expression(elna::boot::make_position(@1), $2,
elna::boot::unary_operator::minus);
}
| operand { $$ = $1; }
expressions:
expression COMMA expressions
@ -337,7 +342,7 @@ expressions:
}
| expression { $$.emplace_back(std::move($1)); }
designator_expression:
designator_expression LEFT_SQUARE expression RIGHT_SQUARE
operand LEFT_SQUARE expression RIGHT_SQUARE
{
$$ = new elna::boot::array_access_expression(elna::boot::make_position(@1), $1, $3);
}
@ -345,7 +350,7 @@ designator_expression:
{
$$ = new elna::boot::field_access_expression(elna::boot::make_position(@2), $1, $3);
}
| designator_expression HAT
| operand HAT
{
$$ = new elna::boot::dereference_expression(elna::boot::make_position(@1), $1);
}
@ -416,20 +421,21 @@ variable_declarations:
variable_part:
/* no variable declarations */ {}
| VAR variable_declarations SEMICOLON { std::swap($$, $2); }
constant_definition: IDENTIFIER EQUALS literal
constant_definition: IDENTIFIER EQUALS literal SEMICOLON
{
$$ = new elna::boot::constant_definition(elna::boot::make_position(@1), $1, $3);
}
constant_definitions:
constant_definition COMMA constant_definitions
constant_definition constant_definitions
{
std::swap($$, $3);
std::swap($$, $2);
$$.emplace($$.cbegin(), std::move($1));
}
| constant_definition { $$.emplace_back(std::move($1)); }
constant_part:
/* no constant definitions */ {}
| CONST constant_definitions SEMICOLON { std::swap($$, $2); }
| CONST {}
| CONST constant_definitions { std::swap($$, $2); }
type_definition: IDENTIFIER EQUALS type_expression
{
$$ = new elna::boot::type_definition(elna::boot::make_position(@1), $1, $3);