aboutsummaryrefslogtreecommitdiff
path: root/boot/parser.yy
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-10-09 23:35:03 +0200
committerEugen Wissner <belka@caraus.de>2026-10-09 23:35:03 +0200
commitda1e84e33de1a9c2cc1745b8f42bc7f0cee8fc5c (patch)
tree6222ecd61c9d6e9d59c6169b99e4a24a5d347fea /boot/parser.yy
parent134d3ac4caff6d87c79b0892e57073594cb0064c (diff)
downloadelna-da1e84e33de1a9c2cc1745b8f42bc7f0cee8fc5c.tar.gz
Add const sections
Diffstat (limited to 'boot/parser.yy')
-rw-r--r--boot/parser.yy56
1 files changed, 53 insertions, 3 deletions
diff --git a/boot/parser.yy b/boot/parser.yy
index 9628443..fa701ec 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -132,6 +132,10 @@ along with GCC; see the file COPYING3. If not see
%type <std::vector<elna::boot::switch_case>> switch_cases;
%type <elna::boot::variable_declaration *> variable_declaration;
%type <std::vector<elna::boot::variable_declaration *>> variable_declarations;
+%type <elna::boot::constant_declaration *> const_declaration;
+%type <std::vector<elna::boot::constant_declaration *>> const_declarations;
+%type <std::pair<std::vector<elna::boot::constant_declaration *>, std::vector<elna::boot::variable_declaration *>>>
+ block_declaration block_declarations;
%type <elna::boot::type_expression *> type_expression return_declaration;
%type <std::vector<elna::boot::type_expression *>> type_expressions;
%type <elna::boot::expression *> expression operand simple_expression procedure_return unary_expression;
@@ -201,6 +205,12 @@ section:
$$.insert($$.end(), variables.begin(), variables.end());
}
+ | "const" const_declarations
+ {
+ std::vector<boot::constant_declaration *> constants = $2;
+
+ $$.insert($$.end(), constants.begin(), constants.end());
+ }
| "threadvar" variable_declarations
{
std::vector<boot::variable_declaration *> variables = $2;
@@ -231,11 +241,39 @@ sections:
procedure_body:
block procedure_return
{ $$ = std::make_unique<boot::procedure_body>(std::move(*$1), $2); }
+block_declaration:
+ "const" const_declarations
+ {
+ $$ = { std::move($2), {} };
+ }
+ | "var" variable_declarations
+ {
+ $$ = { {}, std::move($2) };
+ }
+block_declarations:
+ block_declaration block_declarations
+ {
+ auto [constants, variables] = std::move($1);
+ auto [more_constants, more_variables] = std::move($2);
+
+ constants.insert(constants.end(), more_constants.begin(), more_constants.end());
+ variables.insert(variables.end(), more_variables.begin(), more_variables.end());
+ $$ = { std::move(constants), std::move(variables) };
+ }
+ | block_declaration
+ {
+ $$ = std::move($1);
+ }
block:
- "var" variable_declarations statement_part
- { $$ = std::make_unique<boot::block>($2, $3); }
+ block_declarations statement_part
+ {
+ auto [constants, variables] = std::move($1);
+ $$ = std::make_unique<boot::block>(std::move(constants), std::move(variables), $2);
+ }
| optional_begin_statements
- { $$ = std::make_unique<boot::block>(std::vector<boot::variable_declaration *>(), $1); }
+ {
+ $$ = std::make_unique<boot::block>(std::vector<boot::variable_declaration *>(), $1);
+ }
statement_part:
%empty {}
| "begin" statements { $$ = $2; }
@@ -749,6 +787,18 @@ variable_declarations:
$$ = $2;
$$.insert(std::cbegin($$), $1);
}
+const_declaration:
+ identifier_definition "=" expression
+ {
+ $$ = new boot::constant_declaration(boot::make_position(@$), std::move(*$1), $3);
+ }
+const_declarations:
+ %empty {}
+ | const_declaration const_declarations
+ {
+ $$ = $2;
+ $$.insert(std::cbegin($$), $1);
+ }
import_path:
IDENTIFIER "." import_path
{