Read the input filename from the command line
This commit is contained in:
27
boot/ast.cc
27
boot/ast.cc
@ -92,9 +92,13 @@ namespace boot
|
||||
|
||||
void empty_visitor::visit(block *block)
|
||||
{
|
||||
for (const auto definition : block->value_definitions)
|
||||
for (const auto constant : block->constants)
|
||||
{
|
||||
definition->accept(this);
|
||||
constant->accept(this);
|
||||
}
|
||||
for (const auto variable : block->variables)
|
||||
{
|
||||
variable->accept(this);
|
||||
}
|
||||
for (const auto body_statement : block->body)
|
||||
{
|
||||
@ -474,9 +478,8 @@ namespace boot
|
||||
delete m_body;
|
||||
}
|
||||
|
||||
block::block(const struct position position, std::vector<definition *>&& value_definitions,
|
||||
std::vector<statement *>&& body)
|
||||
: node(position), value_definitions(std::move(value_definitions)), body(std::move(body))
|
||||
block::block(const struct position position)
|
||||
: node(position)
|
||||
{
|
||||
}
|
||||
|
||||
@ -487,9 +490,13 @@ namespace boot
|
||||
|
||||
block::~block()
|
||||
{
|
||||
for (auto definition : this->value_definitions)
|
||||
for (auto variable : this->variables)
|
||||
{
|
||||
delete definition;
|
||||
delete variable;
|
||||
}
|
||||
for (auto constant : this->constants)
|
||||
{
|
||||
delete constant;
|
||||
}
|
||||
for (auto body_statement : this->body)
|
||||
{
|
||||
@ -497,10 +504,8 @@ namespace boot
|
||||
}
|
||||
}
|
||||
|
||||
program::program(const struct position position,
|
||||
std::vector<definition *>&& type_definitions,
|
||||
std::vector<definition *>&& value_definitions, std::vector<statement *>&& body)
|
||||
: block(position, std::move(value_definitions), std::move(body)),
|
||||
program::program(const struct position position, std::vector<definition *>&& type_definitions)
|
||||
: block(position),
|
||||
type_definitions(std::move(type_definitions))
|
||||
{
|
||||
}
|
||||
|
@ -111,49 +111,34 @@
|
||||
%type <elna::boot::cast_expression *> cast_expression;
|
||||
%%
|
||||
program:
|
||||
type_part constant_part procedure_part variable_part BEGIN_BLOCK optional_statements END_BLOCK DOT
|
||||
type_part constant_part variable_part procedure_part BEGIN_BLOCK optional_statements END_BLOCK DOT
|
||||
{
|
||||
std::vector<elna::boot::definition *> definitions($1.size() + $3.size());
|
||||
std::vector<elna::boot::definition *> definitions($1.size() + $4.size());
|
||||
std::vector<elna::boot::definition *>::iterator definition = definitions.begin();
|
||||
std::vector<elna::boot::definition *> value_definitions($2.size() + $4.size());
|
||||
std::vector<elna::boot::definition *>::iterator value_definition = value_definitions.begin();
|
||||
|
||||
for (auto type : $1)
|
||||
{
|
||||
*definition++ = type;
|
||||
}
|
||||
for (auto constant : $2)
|
||||
{
|
||||
*value_definition++ = constant;
|
||||
}
|
||||
for (auto procedure : $3)
|
||||
for (auto procedure : $4)
|
||||
{
|
||||
*definition++ = procedure;
|
||||
}
|
||||
for (auto variable : $4)
|
||||
{
|
||||
*value_definition++ = variable;
|
||||
}
|
||||
auto tree = new elna::boot::program(elna::boot::make_position(@5),
|
||||
std::move(definitions), std::move(value_definitions), std::move($6));
|
||||
auto tree = new elna::boot::program(elna::boot::make_position(@5), std::move(definitions));
|
||||
|
||||
std::swap(tree->constants, $2);
|
||||
std::swap(tree->variables, $3);
|
||||
std::swap(tree->body, $6);
|
||||
|
||||
driver.tree.reset(tree);
|
||||
}
|
||||
block: constant_part variable_part BEGIN_BLOCK optional_statements END_BLOCK
|
||||
{
|
||||
std::vector<elna::boot::definition *> definitions($1.size() + $2.size());
|
||||
std::vector<elna::boot::definition *>::iterator definition = definitions.begin();
|
||||
$$ = new elna::boot::block(elna::boot::make_position(@3));
|
||||
|
||||
for (auto constant : $1)
|
||||
{
|
||||
*definition++ = constant;
|
||||
}
|
||||
for (auto variable : $2)
|
||||
{
|
||||
*definition++ = variable;
|
||||
}
|
||||
$$ = new elna::boot::block(elna::boot::make_position(@3),
|
||||
std::move(definitions), std::move($4));
|
||||
std::swap($$->constants, $1);
|
||||
std::swap($$->variables, $2);
|
||||
std::swap($$->body, $4);
|
||||
}
|
||||
procedure_definition:
|
||||
PROCEDURE IDENTIFIER formal_parameter_list SEMICOLON block SEMICOLON
|
||||
|
Reference in New Issue
Block a user