Replace type expression with traits

This commit is contained in:
2025-02-25 23:39:31 +01:00
parent 85b6843ecf
commit f091344cce
7 changed files with 423 additions and 373 deletions

View File

@@ -75,6 +75,7 @@ along with GCC; see the file COPYING3. If not see
%start program;
%token <std::string> IDENTIFIER
%token <std::string> TRAIT
%token <std::int32_t> INTEGER
%token <std::uint32_t> WORD
%token <float> FLOAT
@@ -125,11 +126,12 @@ along with GCC; see the file COPYING3. If not see
formal_parameters formal_parameter_list;
%type <elna::boot::variable_declaration *> formal_parameter
%type <std::shared_ptr<elna::boot::top_type>> type_expression;
%type <elna::boot::traits_expression *> traits_expression;
%type <elna::boot::expression *> expression operand unary;
%type <std::vector<elna::boot::expression *>> expressions actual_parameter_list;
%type <elna::boot::designator_expression *> designator_expression;
%type <elna::boot::assign_statement *> assign_statement;
%type <elna::boot::call_expression *> call_expression;
%type <elna::boot::procedure_call*> call_expression;
%type <elna::boot::while_statement *> while_statement;
%type <elna::boot::if_statement *> if_statement;
%type <elna::boot::return_statement *> return_statement;
@@ -227,7 +229,7 @@ assign_statement: designator_expression ":=" expression
}
call_expression: designator_expression actual_parameter_list
{
$$ = new elna::boot::call_expression(elna::boot::make_position(@1), $1);
$$ = new elna::boot::procedure_call(elna::boot::make_position(@1), $1);
std::swap($$->arguments, $2);
}
cast_expression: "cast" "(" expression ":" type_expression ")"
@@ -313,10 +315,15 @@ literal:
{
$$ = new elna::boot::number_literal<std::string>(elna::boot::make_position(@1), $1);
}
traits_expression:
TRAIT "(" type_expression ")"
{
$$ = new elna::boot::traits_expression(elna::boot::make_position(@1), $1, $3);
}
operand:
literal { $$ = $1; }
| designator_expression { $$ = $1; }
| "(" type_expression ")" { $$ = new elna::boot::type_expression(elna::boot::make_position(@1), $2); }
| traits_expression { $$ = $1; }
| cast_expression { $$ = $1; }
| call_expression { $$ = $1; }
| "(" expression ")" { $$ = $2; }
@@ -448,10 +455,7 @@ statement:
| while_statement { $$ = $1; }
| if_statement { $$ = $1; }
| return_statement { $$ = $1; }
| call_expression
{
$$ = new elna::boot::call_statement(elna::boot::make_position(@1), $1);
}
| call_expression { $$ = $1; }
| defer_statement { $$ = $1; }
statements:
statement statements