aboutsummaryrefslogtreecommitdiff
path: root/boot/parser.yy
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-23 01:01:03 +0200
committerEugen Wissner <belka@caraus.de>2026-07-23 01:01:03 +0200
commit275fa4bff6d153019b6914fed7127a7d919ca177 (patch)
tree37f8ef0d49c304fe0fde47ce7d4b3ea32ffce707 /boot/parser.yy
parentbd9fe800349dc139cc5841980bcae96e0d18e2db (diff)
downloadelna-275fa4bff6d153019b6914fed7127a7d919ca177.tar.gz
Implement for loop
Diffstat (limited to 'boot/parser.yy')
-rw-r--r--boot/parser.yy55
1 files changed, 29 insertions, 26 deletions
diff --git a/boot/parser.yy b/boot/parser.yy
index bc2ddb5..7d93dde 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -99,12 +99,8 @@ along with GCC; see the file COPYING3. If not see
TYPE "type"
RECORD "record"
EXTERN "extern"
- IF "if"
- WHILE "while"
- DO "do"
- THEN "then"
- ELSE "else"
- ELSIF "elsif"
+ IF "if" THEN "then" ELSE "else" ELSIF "elsif"
+ WHILE "while" DO "do" FOR "for" BY "by"
RETURN "return"
IMPORT "import"
BEGIN_BLOCK "begin"
@@ -135,7 +131,7 @@ along with GCC; see the file COPYING3. If not see
%type <elna::boot::type_expression *> type_expression;
%type <std::vector<elna::boot::type_expression *>> type_expressions;
%type <elna::boot::traits_expression *> traits_expression;
-%type <elna::boot::expression *> expression operand simple_expression procedure_return;
+%type <elna::boot::expression *> expression operand simple_expression procedure_return by_step;
%type <elna::boot::unary_expression *> unary_expression;
%type <elna::boot::binary_expression *> binary_expression;
%type <std::vector<elna::boot::expression *>> expressions actual_parameter_list;
@@ -156,7 +152,6 @@ along with GCC; see the file COPYING3. If not see
%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 <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;
@@ -175,7 +170,7 @@ procedure_body:
{ $$ = std::make_unique<boot::procedure_body>($1, $2, $3); }
statement_part:
- /* no statements */ {}
+ %empty {}
| "begin" statements { $$ = $2; }
identifier:
IDENTIFIER { $$ = std::make_unique<boot::identifier>($1, boot::make_position(@1)); }
@@ -190,7 +185,7 @@ identifier_definitions:
}
| identifier_definition { $$.emplace_back(std::move(*$1)); }
return_declaration:
- /* proper procedure */ {}
+ %empty {}
| ":" "!" { $$ = boot::procedure_type_expression::return_t(std::monostate{}); }
| ":" type_expression { $$ = boot::procedure_type_expression::return_t($2); }
procedure_heading: "(" optional_fields ")" return_declaration
@@ -205,7 +200,7 @@ procedure_declaration:
$$ = new boot::procedure_declaration(boot::make_position(@$), std::move(*$2), $3);
}
procedure_part:
- /* no procedure declarations */ {}
+ %empty {}
| procedure_declaration procedure_part
{
$$ = $2;
@@ -215,8 +210,9 @@ call_expression: designator_expression actual_parameter_list
{
$$ = new boot::procedure_call(boot::make_position(@$), $1, $2);
}
-cast_expression: "cast" "(" expression ":" type_expression ")"
- { $$ = new boot::cast_expression(boot::make_position(@$), $5, $3); }
+by_step:
+ "by" expression { $$ = $2; }
+ | %empty { $$ = nullptr; }
elsif_do_statements:
"elsif" expression "do" statements elsif_do_statements
{
@@ -224,10 +220,10 @@ elsif_do_statements:
$$ = $5;
$$.emplace($$.begin(), branch);
}
- | /* no branches */ {}
+ | %empty {}
else_statements:
"else" statements { $$ = new std::vector<boot::statement *>($2); }
- | { $$ = nullptr; }
+ | %empty { $$ = nullptr; }
elsif_then_statements:
"elsif" expression "then" statements elsif_then_statements
{
@@ -235,7 +231,7 @@ elsif_then_statements:
$$ = $5;
$$.emplace($$.begin(), branch);
}
- | /* no branches */ {}
+ | %empty {}
procedure_return:
"return" expression { $$ = $2; }
| "return" { $$ = nullptr; }
@@ -257,7 +253,10 @@ simple_expression:
literal { $$ = $1; }
| designator_expression { $$ = $1; }
| traits_expression { $$ = $1; }
- | cast_expression { $$ = $1; }
+ | "cast" "(" expression ":" type_expression ")"
+ {
+ $$ = new boot::cast_expression(boot::make_position(@$), $5, $3);
+ }
| call_expression { $$ = $1; }
| "(" expression ")" { $$ = $2; }
| identifier "{" field_initializers "}"
@@ -363,6 +362,7 @@ expressions:
$$.emplace($$.cbegin(), $1);
}
| expression { $$.push_back($1); }
+ | %empty { $$ = std::vector<elna::boot::expression *>(); }
type_expressions:
type_expression "," type_expressions
{
@@ -389,6 +389,10 @@ 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"
+ {
+ $$ = new boot::for_statement(boot::make_position(@$), std::move(*$2), $4, $6, $9, $7);
+ }
| "if" expression "then" statements elsif_then_statements else_statements "end"
{
boot::conditional_statements *then = new boot::conditional_statements($2, $4);
@@ -399,7 +403,7 @@ statement:
{ $$ = new boot::defer_statement(boot::make_position(@$), $2); }
| "case" expression "of" switch_cases else_statements "end"
{ $$ = new boot::case_statement(boot::make_position(@$), $2, $4, $5); }
- | { $$ = new boot::empty_statement(boot::make_position(@$)); }
+ | %empty { $$ = new boot::empty_statement(boot::make_position(@$)); }
switch_case: case_labels ":" statements
{ $$ = { .labels = $1, .statements = $3 }; }
switch_cases:
@@ -434,7 +438,7 @@ required_fields:
| field_declaration { $$.emplace_back($1); }
optional_fields:
required_fields { $$ = $1; }
- | /* no fields */ {}
+ | %empty {}
field_initializer:
identifier ":" expression { $$ = std::make_unique<boot::field_initializer>(std::move(*$1), $3); }
field_initializers:
@@ -505,14 +509,14 @@ variable_declaration:
$$ = new boot::variable_declaration( boot::make_position(@$), $1, shared_type, $5);
}
variable_declarations:
- /* no variable declarations */ {}
+ %empty {}
| variable_declaration variable_declarations
{
$$ = $2;
$$.insert(std::cbegin($$), $1);
}
variable_part:
- /* no variable declarations */ {}
+ %empty {}
| "var" variable_declarations { $$ = $2; }
import_declaration:
IDENTIFIER "." import_declaration
@@ -532,7 +536,7 @@ import_declarations:
$$.emplace_back(new boot::import_declaration(boot::make_position(@$), $1));
}
import_part:
- /* no import declarations */ {}
+ %empty {}
| "import" import_declarations { $$ = $2; }
type_declaration: identifier_definition "=" type_expression
{
@@ -544,13 +548,12 @@ type_declarations:
$$ = $2;
$$.insert($$.cbegin(), $1);
}
- | /* no type definitions */ {}
+ | %empty {}
type_part:
- /* no type definitions */ {}
+ %empty {}
| "type" type_declarations { $$ = $2; }
actual_parameter_list:
- "(" ")" {}
- | "(" expressions ")" { $$ = $2; }
+ "(" expressions ")" { $$ = $2; }
%%
void yy::parser::error(const location_type& loc, const std::string& message)