From bb4f474cb2247e0e314beab5d7d72e673ff4e8b6 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 24 Jul 2026 03:11:32 +0200 Subject: Implement a repeat loop --- boot/parser.yy | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'boot/parser.yy') diff --git a/boot/parser.yy b/boot/parser.yy index 7d93dde..4fdbf84 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -100,7 +100,7 @@ along with GCC; see the file COPYING3. If not see RECORD "record" EXTERN "extern" IF "if" THEN "then" ELSE "else" ELSIF "elsif" - WHILE "while" DO "do" FOR "for" BY "by" + WHILE "while" DO "do" FOR "for" REPEAT "repeat" UNTIL "until" WITH "with" RETURN "return" IMPORT "import" BEGIN_BLOCK "begin" @@ -130,8 +130,7 @@ along with GCC; see the file COPYING3. If not see %type > variable_declarations variable_part; %type type_expression; %type > type_expressions; -%type traits_expression; -%type expression operand simple_expression procedure_return by_step; +%type expression operand simple_expression procedure_return; %type unary_expression; %type binary_expression; %type > expressions actual_parameter_list; @@ -152,7 +151,7 @@ along with GCC; see the file COPYING3. If not see %type > field_initializers; %type > elsif_then_statements elsif_do_statements; %type *> else_statements; -%type > identifier; +%type > identifier with_counter; %type > identifier_definition; %type > identifier_definitions; %type > import_declaration; @@ -210,8 +209,8 @@ call_expression: designator_expression actual_parameter_list { $$ = new boot::procedure_call(boot::make_position(@$), $1, $2); } -by_step: - "by" expression { $$ = $2; } +with_counter: + "with" identifier { $$ = $2; } | %empty { $$ = nullptr; } elsif_do_statements: "elsif" expression "do" statements elsif_do_statements @@ -243,16 +242,14 @@ literal: | CHARACTER { $$ = new boot::literal(boot::make_position(@$), $1.at(0)); } | "nil" { $$ = new boot::literal(boot::make_position(@$), nullptr); } | STRING { $$ = new boot::literal(boot::make_position(@$), $1); } -traits_expression: - TRAIT "(" type_expressions ")" +simple_expression: + literal { $$ = $1; } + | designator_expression { $$ = $1; } + | TRAIT "(" type_expressions ")" { $$ = new boot::traits_expression(boot::make_position(@$), boot::identifier($1, boot::make_position(@1)), $3); } -simple_expression: - literal { $$ = $1; } - | designator_expression { $$ = $1; } - | traits_expression { $$ = $1; } | "cast" "(" expression ":" type_expression ")" { $$ = new boot::cast_expression(boot::make_position(@$), $5, $3); @@ -389,9 +386,13 @@ statement: boot::conditional_statements *body = new boot::conditional_statements($2, $4); $$ = new boot::while_statement(boot::make_position(@$), body, $5); } - | "for" identifier ":=" expression "to" expression by_step "do" statements "end" + | "repeat" statements "until" expression + { + $$ = new boot::repeat_statement(boot::make_position(@$), $2, $4); + } + | "for" identifier "of" expression with_counter "do" statements "end" { - $$ = new boot::for_statement(boot::make_position(@$), std::move(*$2), $4, $6, $9, $7); + $$ = new boot::for_statement(boot::make_position(@$), std::move(*$2), $4, $7, $5.release()); } | "if" expression "then" statements elsif_then_statements else_statements "end" { -- cgit v1.2.3