|
|
|
@ -79,14 +79,13 @@
|
|
|
|
|
%type <elna::source::char_literal *> character_literal;
|
|
|
|
|
%type <elna::source::string_literal *> string_literal;
|
|
|
|
|
%type <elna::source::constant_definition *> constant_definition;
|
|
|
|
|
%type <std::vector<elna::source::constant_definition *>> constant_definition_part constant_definitions;
|
|
|
|
|
%type <std::vector<elna::source::constant_definition *>> constant_part constant_definitions;
|
|
|
|
|
%type <elna::source::declaration *> variable_declaration;
|
|
|
|
|
%type <std::vector<elna::source::declaration *>> variable_declarations variable_declaration_part
|
|
|
|
|
%type <std::vector<elna::source::declaration *>> variable_declarations variable_part
|
|
|
|
|
formal_parameter_list;
|
|
|
|
|
%type <elna::source::type_expression *> type_expression;
|
|
|
|
|
%type <elna::source::expression *> expression pointer summand factor address comparand;
|
|
|
|
|
%type <elna::source::expression *> expression pointer summand factor comparand;
|
|
|
|
|
%type <std::vector<elna::source::expression *>> expressions actual_parameter_list;
|
|
|
|
|
%type <elna::source::variable_expression *> variable_expression;
|
|
|
|
|
%type <elna::source::designator_expression *> designator_expression;
|
|
|
|
|
%type <elna::source::compound_statement *> compound_statement;
|
|
|
|
|
%type <elna::source::assign_statement *> assign_statement;
|
|
|
|
@ -96,13 +95,13 @@
|
|
|
|
|
%type <elna::source::statement *> statement;
|
|
|
|
|
%type <std::vector<elna::source::statement *>> statements optional_statements;
|
|
|
|
|
%type <elna::source::procedure_definition *> procedure_definition;
|
|
|
|
|
%type <std::vector<elna::source::procedure_definition *>> procedure_definitions procedure_definition_part;
|
|
|
|
|
%type <std::vector<elna::source::procedure_definition *>> procedure_definitions procedure_part;
|
|
|
|
|
%type <elna::source::type_definition *> type_definition;
|
|
|
|
|
%type <std::vector<elna::source::type_definition *>> type_definitions type_definition_part;
|
|
|
|
|
%type <std::vector<elna::source::type_definition *>> type_definitions type_part;
|
|
|
|
|
%type <elna::source::block *> block;
|
|
|
|
|
%%
|
|
|
|
|
program:
|
|
|
|
|
type_definition_part constant_definition_part procedure_definition_part variable_declaration_part statement DOT
|
|
|
|
|
type_part constant_part procedure_part variable_part compound_statement DOT
|
|
|
|
|
{
|
|
|
|
|
std::vector<elna::source::definition *> definitions($1.size() + $2.size() + $3.size());
|
|
|
|
|
std::vector<elna::source::definition *>::iterator definition = definitions.begin();
|
|
|
|
@ -122,7 +121,7 @@ program:
|
|
|
|
|
driver.tree = std::make_unique<elna::source::program>(elna::source::position{},
|
|
|
|
|
std::move(definitions), std::move($4), std::move($5));
|
|
|
|
|
}
|
|
|
|
|
block: constant_definition_part variable_declaration_part statement
|
|
|
|
|
block: constant_part variable_part statement
|
|
|
|
|
{
|
|
|
|
|
std::vector<elna::source::definition *> definitions($1.size());
|
|
|
|
|
std::vector<elna::source::definition *>::iterator definition = definitions.begin();
|
|
|
|
@ -148,7 +147,7 @@ procedure_definitions:
|
|
|
|
|
$$.emplace($$.cbegin(), std::move($1));
|
|
|
|
|
}
|
|
|
|
|
| procedure_definition { $$.emplace_back(std::move($1)); }
|
|
|
|
|
procedure_definition_part:
|
|
|
|
|
procedure_part:
|
|
|
|
|
/* no procedure definitions */ {}
|
|
|
|
|
| procedure_definitions { std::swap($$, $1); }
|
|
|
|
|
integer_literal: INTEGER
|
|
|
|
@ -221,20 +220,13 @@ summand:
|
|
|
|
|
$$ = new elna::source::binary_expression(elna::source::make_position(@1),
|
|
|
|
|
$1, $3, '/');
|
|
|
|
|
}
|
|
|
|
|
address:
|
|
|
|
|
pointer HAT
|
|
|
|
|
{
|
|
|
|
|
$$ = new elna::source::unary_expression(elna::source::make_position(@1),
|
|
|
|
|
$1, '^');
|
|
|
|
|
}
|
|
|
|
|
| pointer { $$ = $1; }
|
|
|
|
|
factor:
|
|
|
|
|
AT address
|
|
|
|
|
AT pointer
|
|
|
|
|
{
|
|
|
|
|
$$ = new elna::source::unary_expression(elna::source::make_position(@1),
|
|
|
|
|
$2, '@');
|
|
|
|
|
}
|
|
|
|
|
| address { $$ = $1; }
|
|
|
|
|
| pointer { $$ = $1; }
|
|
|
|
|
comparand:
|
|
|
|
|
summand PLUS summand
|
|
|
|
|
{
|
|
|
|
@ -286,14 +278,23 @@ expressions:
|
|
|
|
|
$$.emplace($$.cbegin(), $1);
|
|
|
|
|
}
|
|
|
|
|
| expression { $$.emplace_back(std::move($1)); }
|
|
|
|
|
variable_expression:
|
|
|
|
|
IDENTIFIER { $$ = new elna::source::variable_expression(elna::source::make_position(@1), $1); }
|
|
|
|
|
designator_expression:
|
|
|
|
|
variable_expression LEFT_SQUARE expression RIGHT_SQUARE
|
|
|
|
|
designator_expression LEFT_SQUARE expression RIGHT_SQUARE
|
|
|
|
|
{
|
|
|
|
|
$$ = new elna::source::array_access_expression(elna::source::make_position(@1), $1, $3);
|
|
|
|
|
}
|
|
|
|
|
| variable_expression { $$ = $1; }
|
|
|
|
|
| designator_expression DOT IDENTIFIER
|
|
|
|
|
{
|
|
|
|
|
$$ = new elna::source::field_access_expression(elna::source::make_position(@1), $1, $3);
|
|
|
|
|
}
|
|
|
|
|
| designator_expression HAT
|
|
|
|
|
{
|
|
|
|
|
$$ = new elna::source::dereference_expression(elna::source::make_position(@1), $1);
|
|
|
|
|
}
|
|
|
|
|
| IDENTIFIER
|
|
|
|
|
{
|
|
|
|
|
$$ = new elna::source::variable_expression(elna::source::make_position(@1), $1);
|
|
|
|
|
}
|
|
|
|
|
statement:
|
|
|
|
|
compound_statement { $$ = $1; }
|
|
|
|
|
| assign_statement { $$ = $1; }
|
|
|
|
@ -334,7 +335,7 @@ variable_declarations:
|
|
|
|
|
$$.emplace($$.cbegin(), $1);
|
|
|
|
|
}
|
|
|
|
|
| variable_declaration { $$.emplace_back(std::move($1)); }
|
|
|
|
|
variable_declaration_part:
|
|
|
|
|
variable_part:
|
|
|
|
|
/* no variable declarations */ {}
|
|
|
|
|
| VAR variable_declarations SEMICOLON { std::swap($$, $2); }
|
|
|
|
|
constant_definition: IDENTIFIER EQUALS integer_literal
|
|
|
|
@ -348,7 +349,7 @@ constant_definitions:
|
|
|
|
|
$$.emplace($$.cbegin(), std::move($1));
|
|
|
|
|
}
|
|
|
|
|
| constant_definition { $$.emplace_back(std::move($1)); }
|
|
|
|
|
constant_definition_part:
|
|
|
|
|
constant_part:
|
|
|
|
|
/* no constant definitions */ {}
|
|
|
|
|
| CONST constant_definitions SEMICOLON { std::swap($$, $2); }
|
|
|
|
|
type_definition: IDENTIFIER EQUALS type_expression
|
|
|
|
@ -362,7 +363,7 @@ type_definitions:
|
|
|
|
|
$$.emplace($$.cbegin(), std::move($1));
|
|
|
|
|
}
|
|
|
|
|
| type_definition { $$.emplace_back(std::move($1)); }
|
|
|
|
|
type_definition_part:
|
|
|
|
|
type_part:
|
|
|
|
|
/* no type definitions */ {}
|
|
|
|
|
| TYPE type_definitions SEMICOLON { std::swap($$, $2); }
|
|
|
|
|
formal_parameter_list:
|
|
|
|
|