Implement parameterless prcoedures
This commit is contained in:
@ -7,7 +7,7 @@ namespace elna
|
||||
{
|
||||
namespace source
|
||||
{
|
||||
void empty_visitor::visit(declaration *)
|
||||
void empty_visitor::visit(variable_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
@ -69,9 +69,9 @@ namespace source
|
||||
{
|
||||
constant->accept(this);
|
||||
}
|
||||
for (const auto& block_declaration : block->declarations())
|
||||
for (const auto& definition : block->value_definitions)
|
||||
{
|
||||
block_declaration->accept(this);
|
||||
definition->accept(this);
|
||||
}
|
||||
block->body().accept(this);
|
||||
}
|
||||
@ -344,23 +344,23 @@ namespace source
|
||||
}
|
||||
}
|
||||
|
||||
declaration::declaration(const struct position position, const std::string& identifier,
|
||||
variable_declaration::variable_declaration(const struct position position, const std::string& identifier,
|
||||
type_expression *type)
|
||||
: definition(position, identifier), m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
declaration::~declaration()
|
||||
variable_declaration::~variable_declaration()
|
||||
{
|
||||
delete m_type;
|
||||
}
|
||||
|
||||
void declaration::accept(parser_visitor *visitor)
|
||||
void variable_declaration::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
type_expression& declaration::type()
|
||||
type_expression& variable_declaration::type()
|
||||
{
|
||||
return *m_type;
|
||||
}
|
||||
@ -412,7 +412,7 @@ namespace source
|
||||
return *m_body;
|
||||
}
|
||||
|
||||
std::vector<declaration *>& procedure_definition::parameters()
|
||||
std::vector<variable_declaration *>& procedure_definition::parameters()
|
||||
{
|
||||
return m_parameters;
|
||||
}
|
||||
@ -448,10 +448,10 @@ namespace source
|
||||
}
|
||||
|
||||
block::block(const struct position position, std::vector<definition *>&& definitions,
|
||||
std::vector<declaration *>&& declarations,
|
||||
std::vector<definition *>&& value_definitions,
|
||||
statement *body)
|
||||
: node(position), m_definitions(std::move(definitions)),
|
||||
m_declarations(std::move(declarations)), m_body(std::move(body))
|
||||
m_body(std::move(body)), value_definitions(std::move(value_definitions))
|
||||
{
|
||||
}
|
||||
|
||||
@ -460,19 +460,14 @@ namespace source
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
statement& block::body()
|
||||
{
|
||||
return *m_body;
|
||||
}
|
||||
|
||||
std::vector<definition *>& block::definitions()
|
||||
{
|
||||
return m_definitions;
|
||||
}
|
||||
|
||||
std::vector<declaration *>& block::declarations()
|
||||
statement& block::body()
|
||||
{
|
||||
return m_declarations;
|
||||
return *m_body;
|
||||
}
|
||||
|
||||
block::~block()
|
||||
@ -481,17 +476,16 @@ namespace source
|
||||
{
|
||||
delete definition;
|
||||
}
|
||||
for (auto declaration : m_declarations)
|
||||
for (auto definition : value_definitions)
|
||||
{
|
||||
delete declaration;
|
||||
delete definition;
|
||||
}
|
||||
delete m_body;
|
||||
}
|
||||
|
||||
program::program(const struct position position, std::vector<definition *>&& definitions,
|
||||
std::vector<declaration *>&& declarations,
|
||||
statement *body)
|
||||
: block(position, std::move(definitions), std::move(declarations), body)
|
||||
std::vector<definition *>&& value_definitions, statement *body)
|
||||
: block(position, std::move(definitions), std::move(value_definitions), body)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,8 @@
|
||||
%type <elna::source::string_literal *> string_literal;
|
||||
%type <elna::source::constant_definition *> constant_definition;
|
||||
%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_part
|
||||
%type <elna::source::variable_declaration *> variable_declaration;
|
||||
%type <std::vector<elna::source::variable_declaration *>> variable_declarations variable_part
|
||||
formal_parameter_list;
|
||||
%type <elna::source::type_expression *> type_expression;
|
||||
%type <elna::source::expression *> expression pointer summand factor comparand;
|
||||
@ -105,35 +105,45 @@
|
||||
program:
|
||||
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 *> definitions($1.size() + $3.size());
|
||||
std::vector<elna::source::definition *>::iterator definition = definitions.begin();
|
||||
std::vector<elna::source::definition *> value_definitions($2.size() + $4.size());
|
||||
std::vector<elna::source::definition *>::iterator value_definition = value_definitions.begin();
|
||||
|
||||
for (auto& type : $1)
|
||||
for (auto type : $1)
|
||||
{
|
||||
*definition++ = type;
|
||||
}
|
||||
for (auto& constant : $2)
|
||||
for (auto constant : $2)
|
||||
{
|
||||
*definition++ = constant;
|
||||
*value_definition++ = constant;
|
||||
}
|
||||
for (auto& procedure : $3)
|
||||
for (auto procedure : $3)
|
||||
{
|
||||
*definition++ = procedure;
|
||||
}
|
||||
for (auto variable : $4)
|
||||
{
|
||||
*value_definition++ = variable;
|
||||
}
|
||||
driver.tree = std::make_unique<elna::source::program>(elna::source::position{},
|
||||
std::move(definitions), std::move($4), std::move($5));
|
||||
std::move(definitions), std::move(value_definitions), std::move($5));
|
||||
}
|
||||
block: constant_part variable_part statement
|
||||
{
|
||||
std::vector<elna::source::definition *> definitions($1.size());
|
||||
std::vector<elna::source::definition *> definitions($1.size() + $2.size());
|
||||
std::vector<elna::source::definition *>::iterator definition = definitions.begin();
|
||||
|
||||
for (auto& constant : $1)
|
||||
for (auto constant : $1)
|
||||
{
|
||||
*definition++ = constant;
|
||||
}
|
||||
for (auto variable : $2)
|
||||
{
|
||||
*definition++ = variable;
|
||||
}
|
||||
$$ = new elna::source::block(elna::source::position{},
|
||||
std::move(definitions), std::move($2), std::move($3));
|
||||
{}, std::move(definitions), std::move($3));
|
||||
};
|
||||
procedure_definition:
|
||||
PROCEDURE IDENTIFIER formal_parameter_list SEMICOLON block SEMICOLON
|
||||
@ -335,7 +345,7 @@ type_expression:
|
||||
}
|
||||
variable_declaration: IDENTIFIER COLON type_expression
|
||||
{
|
||||
$$ = new elna::source::declaration(elna::source::make_position(@1), $1, $3);
|
||||
$$ = new elna::source::variable_declaration(elna::source::make_position(@1), $1, $3);
|
||||
};
|
||||
variable_declarations:
|
||||
variable_declaration COMMA variable_declarations
|
||||
|
Reference in New Issue
Block a user