aboutsummaryrefslogtreecommitdiff
path: root/boot/parser.yy
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-09-02 13:31:04 +0200
committerEugen Wissner <belka@caraus.de>2026-09-07 10:53:02 +0200
commit47521ad6d85f9bd6caee39696ce40dff82cfa50d (patch)
treecf5813033a440c6ac374948894d5dd70e0712cdb /boot/parser.yy
parent0fada11e99da430e9a056e46da9f0e110df6c45c (diff)
downloadelna-47521ad6d85f9bd6caee39696ce40dff82cfa50d.tar.gz
Implement program entry point
Diffstat (limited to 'boot/parser.yy')
-rw-r--r--boot/parser.yy53
1 files changed, 31 insertions, 22 deletions
diff --git a/boot/parser.yy b/boot/parser.yy
index b53a94c..dc1d4e8 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -93,7 +93,7 @@ along with GCC; see the file COPYING3. If not see
EXCLAMATION "!" ARROW "->"
AT "@" HAT "^"
COLON ":" SEMICOLON ";" DOT "." COMMA ","
-%token NOT "~"
+%token PROGRAM "program"
CAST "cast"
NIL "nil"
CONST "const"
@@ -113,7 +113,7 @@ along with GCC; see the file COPYING3. If not see
OF "of"
TO "to"
PIPE "|"
-%token OR "or" AND "&" XOR "xor"
+%token NOT "~" OR "or" AND "&" XOR "xor"
EQUALS "=" NOT_EQUAL "<>" LESS_THAN "<" GREATER_THAN ">" LESS_EQUAL "<=" GREATER_EQUAL ">="
SHIFT_LEFT "<<" SHIFT_RIGHT ">>"
PLUS "+" MINUS "-"
@@ -125,7 +125,7 @@ along with GCC; see the file COPYING3. If not see
%left "+" "-"
%left "*" "/" "%"
-%type <elna::boot::literal_expression *> literal;
+%type <std::unique_ptr<elna::boot::literal_expression>> literal;
%type <std::vector<elna::boot::expression *>> case_labels;
%type <elna::boot::switch_case> switch_case;
%type <std::vector<elna::boot::switch_case>> switch_cases;
@@ -162,9 +162,15 @@ along with GCC; see the file COPYING3. If not see
%type <std::unique_ptr<elna::boot::array_type_expression>> array_type_expression;
%%
program:
- import_part type_part variable_part procedure_part statement_part "end" "."
+ import_part type_part variable_part procedure_part "end" "."
{
- boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4, $5);
+ boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4);
+ driver.tree.reset(tree);
+ }
+ | import_part type_part variable_part procedure_part "program" "(" ")" statement_part "end" "."
+ {
+ boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4,
+ boot::procedure_body({}, std::move($8)));
driver.tree.reset(tree);
}
procedure_body:
@@ -242,91 +248,94 @@ literal:
INTEGER
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed, false);
}
| INTEGER8
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| INTEGER16
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| INTEGER32
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| INTEGER64
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| WORD
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed, false);
}
| WORD8
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| WORD16
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| WORD32
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| WORD64
{
auto [magnitude, wants_signed] = $1;
- $$ = new boot::literal<boot::integer_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::integer_literal>>(boot::make_position(@$),
boot::integer_literal::from(magnitude), wants_signed);
}
| SINGLE
{
- $$ = new boot::literal<boot::float_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::float_literal>>(boot::make_position(@$),
boot::float_literal::from($1), boot::integer_sign::unmarked);
}
| DOUBLE
{
- $$ = new boot::literal<boot::float_literal>(boot::make_position(@$),
+ $$ = std::make_unique<boot::literal<boot::float_literal>>(boot::make_position(@$),
boot::float_literal::from($1), boot::integer_sign::unmarked);
}
| BOOLEAN
{
- $$ = new boot::literal<bool>(boot::make_position(@$), $1, boot::integer_sign::_unsigned);
+ $$ = std::make_unique<boot::literal<bool>>(boot::make_position(@$), $1, boot::integer_sign::_unsigned);
}
| CHARACTER
{
- $$ = new boot::literal<std::uint32_t>(boot::make_position(@$), $1, boot::integer_sign::_unsigned);
+ $$ = std::make_unique<boot::literal<std::uint32_t>>(boot::make_position(@$),
+ $1, boot::integer_sign::_unsigned);
}
| "nil"
{
- $$ = new boot::literal<std::nullptr_t>(boot::make_position(@$), nullptr, boot::integer_sign::_unsigned);
+ $$ = std::make_unique<boot::literal<std::nullptr_t>>(boot::make_position(@$),
+ nullptr, boot::integer_sign::_unsigned);
}
| STRING
{
- $$ = new boot::literal<std::string>(boot::make_position(@$), $1, boot::integer_sign::_unsigned);
+ $$ = std::make_unique<boot::literal<std::string>>(boot::make_position(@$),
+ $1, boot::integer_sign::_unsigned);
}
simple_expression:
- literal { $$ = $1; }
+ literal { $$ = $1.release(); }
| designator_expression { $$ = $1; }
| TRAIT "(" type_expressions ")"
{