Add lexer and parser sources
This commit is contained in:
@ -133,8 +133,8 @@ along with GCC; see the file COPYING3. If not see
|
||||
%type <std::vector<elna::boot::expression *>> case_labels;
|
||||
%type <elna::boot::switch_case> switch_case;
|
||||
%type <std::vector<elna::boot::switch_case>> switch_cases;
|
||||
%type <elna::boot::constant_definition *> constant_definition;
|
||||
%type <std::vector<elna::boot::constant_definition *>> constant_part constant_definitions;
|
||||
%type <elna::boot::constant_declaration *> constant_declaration;
|
||||
%type <std::vector<elna::boot::constant_declaration *>> constant_part constant_declarations;
|
||||
%type <std::vector<elna::boot::variable_declaration *>> variable_declarations variable_part variable_declaration;
|
||||
%type <elna::boot::type_expression *> type_expression;
|
||||
%type <std::vector<elna::boot::type_expression *>> type_expressions;
|
||||
@ -148,12 +148,12 @@ along with GCC; see the file COPYING3. If not see
|
||||
%type <elna::boot::return_statement *> return_statement;
|
||||
%type <elna::boot::statement *> statement;
|
||||
%type <std::vector<elna::boot::statement *>> required_statements optional_statements statement_part;
|
||||
%type <elna::boot::procedure_definition *> procedure_definition;
|
||||
%type <elna::boot::procedure_declaration *> procedure_declaration;
|
||||
%type <std::pair<std::vector<std::string>, elna::boot::procedure_type_expression *>> procedure_heading;
|
||||
%type <elna::boot::procedure_type_expression::return_t> return_declaration;
|
||||
%type <std::vector<elna::boot::procedure_definition *>> procedure_definitions procedure_part;
|
||||
%type <elna::boot::type_definition *> type_definition;
|
||||
%type <std::vector<elna::boot::type_definition *>> type_definitions type_part;
|
||||
%type <std::vector<elna::boot::procedure_declaration *>> procedure_declarations procedure_part;
|
||||
%type <elna::boot::type_declaration *> type_declaration;
|
||||
%type <std::vector<elna::boot::type_declaration *>> type_declarations type_part;
|
||||
%type <std::unique_ptr<elna::boot::block>> block;
|
||||
%type <elna::boot::field_declaration> field_declaration formal_parameter;
|
||||
%type <std::vector<std::pair<std::string, elna::boot::type_expression *>>>
|
||||
@ -167,28 +167,28 @@ along with GCC; see the file COPYING3. If not see
|
||||
%type <std::vector<elna::boot::import_declaration *>> import_declarations import_part;
|
||||
%%
|
||||
program:
|
||||
"program" import_part constant_part type_part variable_part procedure_part "begin" optional_statements "end" "."
|
||||
"program" ";" import_part constant_part type_part variable_part procedure_part statement_part "end" "."
|
||||
{
|
||||
auto tree = new boot::program(boot::make_position(@7));
|
||||
auto tree = new boot::program(boot::make_position(@1));
|
||||
|
||||
std::swap(tree->imports, $2);
|
||||
std::swap(tree->constants, $3);
|
||||
std::swap(tree->types , $4);
|
||||
std::swap(tree->variables, $5);
|
||||
std::swap(tree->procedures, $6);
|
||||
std::swap(tree->imports, $3);
|
||||
std::swap(tree->constants, $4);
|
||||
std::swap(tree->types , $5);
|
||||
std::swap(tree->variables, $6);
|
||||
std::swap(tree->procedures, $7);
|
||||
std::swap(tree->body, $8);
|
||||
|
||||
driver.tree.reset(tree);
|
||||
}
|
||||
| "module" import_part constant_part type_part variable_part procedure_part "end" "."
|
||||
| "module" ";" import_part constant_part type_part variable_part procedure_part "end" "."
|
||||
{
|
||||
auto tree = new boot::program(boot::make_position(@7));
|
||||
auto tree = new boot::program(boot::make_position(@1));
|
||||
|
||||
std::swap(tree->imports, $2);
|
||||
std::swap(tree->constants, $3);
|
||||
std::swap(tree->types , $4);
|
||||
std::swap(tree->variables, $5);
|
||||
std::swap(tree->procedures, $6);
|
||||
std::swap(tree->imports, $3);
|
||||
std::swap(tree->constants, $4);
|
||||
std::swap(tree->types , $5);
|
||||
std::swap(tree->variables, $6);
|
||||
std::swap(tree->procedures, $7);
|
||||
|
||||
driver.tree.reset(tree);
|
||||
}
|
||||
@ -228,27 +228,27 @@ procedure_heading: formal_parameter_list return_declaration
|
||||
$$.second->parameters.push_back(type);
|
||||
}
|
||||
}
|
||||
procedure_definition:
|
||||
"proc" identifier_definition procedure_heading ";" block
|
||||
procedure_declaration:
|
||||
"proc" identifier_definition procedure_heading ";" block ";"
|
||||
{
|
||||
$$ = new boot::procedure_definition(boot::make_position(@1), std::move($2), $3.second, std::move(*$5));
|
||||
$$ = new boot::procedure_declaration(boot::make_position(@1), std::move($2), $3.second, std::move(*$5));
|
||||
std::swap($3.first, $$->parameter_names);
|
||||
}
|
||||
| "proc" identifier_definition procedure_heading ";" "extern"
|
||||
| "proc" identifier_definition procedure_heading ";" "extern" ";"
|
||||
{
|
||||
$$ = new boot::procedure_definition(boot::make_position(@1), std::move($2), $3.second);
|
||||
$$ = new boot::procedure_declaration(boot::make_position(@1), std::move($2), $3.second);
|
||||
std::swap($3.first, $$->parameter_names);
|
||||
}
|
||||
procedure_definitions:
|
||||
procedure_definition procedure_definitions
|
||||
procedure_declarations:
|
||||
procedure_declaration procedure_declarations
|
||||
{
|
||||
std::swap($$, $2);
|
||||
$$.emplace($$.cbegin(), std::move($1));
|
||||
}
|
||||
| procedure_definition { $$.emplace_back(std::move($1)); }
|
||||
| procedure_declaration { $$.emplace_back(std::move($1)); }
|
||||
procedure_part:
|
||||
/* no procedure definitions */ {}
|
||||
| procedure_definitions { std::swap($$, $1); }
|
||||
| procedure_declarations { std::swap($$, $1); }
|
||||
call_expression: designator_expression actual_parameter_list
|
||||
{
|
||||
$$ = new boot::procedure_call(boot::make_position(@1), $1);
|
||||
@ -454,9 +454,9 @@ optional_statements:
|
||||
field_declaration:
|
||||
IDENTIFIER ":" type_expression { $$ = std::make_pair($1, $3); }
|
||||
required_fields:
|
||||
field_declaration required_fields
|
||||
field_declaration ";" required_fields
|
||||
{
|
||||
std::swap($$, $2);
|
||||
std::swap($$, $3);
|
||||
$$.emplace($$.cbegin(), $1);
|
||||
}
|
||||
| field_declaration { $$.emplace_back($1); }
|
||||
@ -501,7 +501,7 @@ identifiers:
|
||||
$$.emplace($$.cbegin(), std::move($1));
|
||||
}
|
||||
| IDENTIFIER { $$.emplace_back(std::move($1)); }
|
||||
variable_declaration: identifier_definitions ":" type_expression
|
||||
variable_declaration: identifier_definitions ":" type_expression ";"
|
||||
{
|
||||
std::shared_ptr<boot::type_expression> shared_type{ $3 };
|
||||
|
||||
@ -523,12 +523,12 @@ variable_declarations:
|
||||
variable_part:
|
||||
/* no variable declarations */ {}
|
||||
| "var" variable_declarations { std::swap($$, $2); }
|
||||
constant_definition: identifier_definition ":=" expression
|
||||
constant_declaration: identifier_definition ":=" expression ";"
|
||||
{
|
||||
$$ = new boot::constant_definition(boot::make_position(@1), std::move($1), $3);
|
||||
$$ = new boot::constant_declaration(boot::make_position(@1), std::move($1), $3);
|
||||
}
|
||||
constant_definitions:
|
||||
constant_definition constant_definitions
|
||||
constant_declarations:
|
||||
constant_declaration constant_declarations
|
||||
{
|
||||
std::swap($$, $2);
|
||||
$$.insert($$.cbegin(), $1);
|
||||
@ -536,7 +536,7 @@ constant_definitions:
|
||||
| /* no constant definitions */ {}
|
||||
constant_part:
|
||||
/* no constant definitions */ {}
|
||||
| "const" constant_definitions { std::swap($$, $2); }
|
||||
| "const" constant_declarations { std::swap($$, $2); }
|
||||
import_declaration:
|
||||
IDENTIFIER "." import_declaration
|
||||
{
|
||||
@ -545,8 +545,7 @@ import_declaration:
|
||||
}
|
||||
| IDENTIFIER { $$.emplace_back(std::move($1)); }
|
||||
import_declarations:
|
||||
/* no import declarations */ {}
|
||||
| import_declaration "," import_declarations
|
||||
import_declaration "," import_declarations
|
||||
{
|
||||
std::swap($$, $3);
|
||||
$$.emplace($$.cbegin(), new boot::import_declaration(boot::make_position(@1), std::move($1)));
|
||||
@ -557,13 +556,13 @@ import_declarations:
|
||||
}
|
||||
import_part:
|
||||
/* no import declarations */ {}
|
||||
| "import" import_declarations { std::swap($$, $2); }
|
||||
type_definition: identifier_definition "=" type_expression
|
||||
| "import" import_declarations ";" { std::swap($$, $2); }
|
||||
type_declaration: identifier_definition "=" type_expression ";"
|
||||
{
|
||||
$$ = new boot::type_definition(boot::make_position(@1), std::move($1), $3);
|
||||
$$ = new boot::type_declaration(boot::make_position(@1), std::move($1), $3);
|
||||
}
|
||||
type_definitions:
|
||||
type_definition type_definitions
|
||||
type_declarations:
|
||||
type_declaration type_declarations
|
||||
{
|
||||
std::swap($$, $2);
|
||||
$$.insert($$.cbegin(), $1);
|
||||
@ -571,7 +570,7 @@ type_definitions:
|
||||
| /* no type definitions */ {}
|
||||
type_part:
|
||||
/* no type definitions */ {}
|
||||
| "type" type_definitions { std::swap($$, $2); }
|
||||
| "type" type_declarations { std::swap($$, $2); }
|
||||
formal_parameter:
|
||||
IDENTIFIER ":" type_expression { $$ = std::make_pair($1, $3); }
|
||||
formal_parameter_list:
|
||||
|
Reference in New Issue
Block a user