Support else in if then conditions

This commit is contained in:
2024-12-30 23:12:47 +01:00
parent c558c3d6b4
commit 75a691134f
8 changed files with 97 additions and 17 deletions

View File

@@ -59,7 +59,7 @@
%token <std::string> IDENTIFIER "identifier"
%token <std::int32_t> NUMBER "number"
%token <bool> BOOLEAN
%token IF THEN WHILE DO
%token IF WHILE DO
%token CONST VAR PROCEDURE
%token BEGIN_BLOCK END_BLOCK
%token LEFT_PAREN RIGHT_PAREN SEMICOLON DOT COMMA
@@ -67,6 +67,9 @@
%token PLUS MINUS MULTIPLICATION DIVISION
%token ASSIGNMENT COLON HAT AT
%precedence THEN
%precedence ELSE
%type <std::unique_ptr<elna::source::integer_literal>> integer_literal;
%type <std::unique_ptr<elna::source::boolean_literal>> boolean_literal;
%type <std::unique_ptr<elna::source::constant_definition>> constant_definition;
@@ -169,6 +172,11 @@ if_statement:
$$ = std::make_unique<elna::source::if_statement>(elna::source::make_position(@1),
std::move($2), std::move($4));
}
| IF expression THEN statement ELSE statement
{
$$ = std::make_unique<elna::source::if_statement>(elna::source::make_position(@1),
std::move($2), std::move($4), std::move($6));
}
pointer:
integer_literal { $$ = std::move($1); }
| boolean_literal { $$ = std::move($1); }