Implement elsif do

This commit is contained in:
2025-02-17 19:36:25 +01:00
parent 994b91e0e5
commit 39750f4656
8 changed files with 46 additions and 58 deletions

View File

@ -119,7 +119,7 @@ along with GCC; see the file COPYING3. If not see
%type <elna::boot::block *> block;
%type <elna::boot::field_t> field_declaration;
%type <std::vector<std::pair<std::string, std::shared_ptr<elna::boot::top_type>>>> optional_fields fields;
%type <std::vector<elna::boot::conditional_statements *>> elsif_statement_list;
%type <std::vector<elna::boot::conditional_statements *>> elsif_then_statements elsif_do_statements;
%type <elna::boot::cast_expression *> cast_expression;
%type <elna::boot::defer_statement *> defer_statement;
%type <std::pair<std::string, bool>> identifier_definition;
@ -201,14 +201,24 @@ cast_expression: CAST LEFT_PAREN expression COLON type_expression RIGHT_PAREN
{
$$ = new elna::boot::cast_expression(elna::boot::make_position(@1), $5, $3);
}
while_statement: WHILE expression DO optional_statements END_BLOCK
elsif_do_statements:
ELSIF expression DO optional_statements elsif_do_statements
{
elna::boot::conditional_statements *branch = new elna::boot::conditional_statements($2);
std::swap(branch->statements, $4);
std::swap($5, $$);
$$.emplace($$.begin(), branch);
}
| {}
while_statement: WHILE expression DO optional_statements elsif_do_statements END_BLOCK
{
auto body = new elna::boot::conditional_statements($2);
std::swap($4, body->statements);
$$ = new elna::boot::while_statement(elna::boot::make_position(@1), body);
std::swap($5, $$->branches);
}
elsif_statement_list:
ELSIF expression THEN optional_statements elsif_statement_list
elsif_then_statements:
ELSIF expression THEN optional_statements elsif_then_statements
{
elna::boot::conditional_statements *branch = new elna::boot::conditional_statements($2);
std::swap(branch->statements, $4);
@ -217,14 +227,14 @@ elsif_statement_list:
}
| {}
if_statement:
IF expression THEN optional_statements elsif_statement_list END_BLOCK
IF expression THEN optional_statements elsif_then_statements END_BLOCK
{
auto then = new elna::boot::conditional_statements($2);
std::swap($4, then->statements);
$$ = new elna::boot::if_statement(elna::boot::make_position(@1), then);
std::swap($5, $$->branches);
}
| IF expression THEN optional_statements elsif_statement_list ELSE optional_statements END_BLOCK
| IF expression THEN optional_statements elsif_then_statements ELSE optional_statements END_BLOCK
{
auto then = new elna::boot::conditional_statements($2);
std::swap($4, then->statements);