Handle array variable declaration

This commit is contained in:
2025-01-06 15:08:23 +01:00
parent e8747a803f
commit ed1bb621d6
6 changed files with 178 additions and 77 deletions

View File

@@ -63,7 +63,7 @@
%token <std::string> STRING "string"
%token <bool> BOOLEAN
%token IF WHILE DO
%token CONST VAR PROCEDURE
%token CONST VAR PROCEDURE ARRAY OF
%token BEGIN_BLOCK END_BLOCK
%token LEFT_PAREN RIGHT_PAREN LEFT_SQUARE RIGHT_SQUARE SEMICOLON DOT COMMA
%token GREATER_EQUAL LESS_EQUAL LESS_THAN GREATER_THAN NOT_EQUAL EQUALS
@@ -83,7 +83,7 @@
%type <elna::source::declaration *> variable_declaration;
%type <std::vector<elna::source::declaration *>> variable_declarations variable_declaration_part
formal_parameter_list;
%type <elna::source::basic_type_expression *> type_expression;
%type <elna::source::type_expression *> type_expression;
%type <elna::source::expression *> expression pointer summand factor address comparand;
%type <std::vector<elna::source::expression *>> expressions actual_parameter_list;
%type <elna::source::variable_expression *> variable_expression;
@@ -299,7 +299,11 @@ optional_statements:
statements { std::swap($$, $1); }
| /* no statements */ {}
type_expression:
IDENTIFIER
ARRAY INTEGER OF type_expression
{
$$ = new elna::source::array_type_expression(elna::source::make_position(@1), $4, $2);
}
| IDENTIFIER
{
$$ = new elna::source::basic_type_expression(elna::source::make_position(@1), $1);
}