Label loops
This commit is contained in:
86
boot/ast.cc
86
boot/ast.cc
@ -33,36 +33,6 @@ namespace elna::boot
|
||||
return this->source_position;
|
||||
}
|
||||
|
||||
assign_statement *statement::is_assign()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if_statement *statement::is_if()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
while_statement *statement::is_while()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return_statement *statement::is_return()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
defer_statement *statement::is_defer()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
procedure_call *statement::is_call_statement()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cast_expression *expression::is_cast()
|
||||
{
|
||||
return nullptr;
|
||||
@ -447,11 +417,6 @@ namespace elna::boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
defer_statement *defer_statement::is_defer()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
defer_statement::~defer_statement()
|
||||
{
|
||||
for (statement *body_statement : statements)
|
||||
@ -676,11 +641,6 @@ namespace elna::boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
procedure_call *procedure_call::is_call_statement()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
procedure_call *procedure_call::is_call_expression()
|
||||
{
|
||||
return this;
|
||||
@ -754,8 +714,8 @@ namespace elna::boot
|
||||
return this;
|
||||
}
|
||||
|
||||
conditional_statements::conditional_statements(expression *prerequisite)
|
||||
: m_prerequisite(prerequisite)
|
||||
conditional_statements::conditional_statements(expression *prerequisite, std::vector<statement *>&& statements)
|
||||
: m_prerequisite(prerequisite), statements(std::move(statements))
|
||||
{
|
||||
}
|
||||
|
||||
@ -783,11 +743,6 @@ namespace elna::boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
return_statement *return_statement::is_return()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
return_statement::~return_statement()
|
||||
{
|
||||
delete this->return_expression;
|
||||
@ -820,11 +775,6 @@ namespace elna::boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
assign_statement *assign_statement::is_assign()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
variable_expression *designator_expression::is_variable()
|
||||
{
|
||||
return nullptr;
|
||||
@ -871,11 +821,6 @@ namespace elna::boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
if_statement *if_statement::is_if()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
conditional_statements& if_statement::body()
|
||||
{
|
||||
return *m_body;
|
||||
@ -891,8 +836,26 @@ namespace elna::boot
|
||||
delete this->alternative;
|
||||
}
|
||||
|
||||
while_statement::while_statement(const struct position position, conditional_statements *body)
|
||||
: node(position), m_body(body)
|
||||
escape_statement::escape_statement(const struct position position,
|
||||
escape_direction direction, const std::string& label)
|
||||
: node(position), direction(direction), label(label)
|
||||
{
|
||||
}
|
||||
|
||||
void escape_statement::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
while_statement::while_statement(const struct position position, conditional_statements *body,
|
||||
std::vector<conditional_statements *>&& branches)
|
||||
: node(position), m_body(body), branches(std::move(branches))
|
||||
{
|
||||
}
|
||||
|
||||
while_statement::while_statement(const struct position position, conditional_statements *body,
|
||||
std::vector<conditional_statements *>&& branches, const std::string& label)
|
||||
: node(position), m_body(body), branches(std::move(branches)), label(label)
|
||||
{
|
||||
}
|
||||
|
||||
@ -901,11 +864,6 @@ namespace elna::boot
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
while_statement *while_statement::is_while()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
conditional_statements& while_statement::body()
|
||||
{
|
||||
return *m_body;
|
||||
|
@ -125,6 +125,12 @@ or {
|
||||
return {
|
||||
return yy::parser::make_RETURN(this->location);
|
||||
}
|
||||
break {
|
||||
return yy::parser::make_BREAK(this->location);
|
||||
}
|
||||
repeat {
|
||||
return yy::parser::make_REPEAT(this->location);
|
||||
}
|
||||
cast {
|
||||
return yy::parser::make_CAST(this->location);
|
||||
}
|
||||
|
@ -108,6 +108,8 @@ along with GCC; see the file COPYING3. If not see
|
||||
ELSE "else"
|
||||
ELSIF "elsif"
|
||||
RETURN "return"
|
||||
REPEAT "repeat"
|
||||
BREAK "break"
|
||||
BEGIN_BLOCK "begin"
|
||||
END_BLOCK "end"
|
||||
DEFER "defer"
|
||||
@ -247,8 +249,7 @@ cast_expression: "cast" "(" expression ":" type_expression ")"
|
||||
elsif_do_statements:
|
||||
"elsif" expression "do" statements elsif_do_statements
|
||||
{
|
||||
boot::conditional_statements *branch = new boot::conditional_statements($2);
|
||||
std::swap(branch->statements, $4);
|
||||
boot::conditional_statements *branch = new boot::conditional_statements($2, std::move($4));
|
||||
std::swap($5, $$);
|
||||
$$.emplace($$.begin(), branch);
|
||||
}
|
||||
@ -256,18 +257,21 @@ elsif_do_statements:
|
||||
else_statements:
|
||||
"else" statements { $$ = new std::vector<boot::statement *>(std::move($2)); }
|
||||
| { $$ = nullptr; }
|
||||
while_statement: "while" expression "do" statements elsif_do_statements "end"
|
||||
while_statement:
|
||||
"while" expression "do" statements elsif_do_statements "end"
|
||||
{
|
||||
auto body = new boot::conditional_statements($2);
|
||||
std::swap($4, body->statements);
|
||||
$$ = new boot::while_statement(boot::make_position(@1), body);
|
||||
std::swap($5, $$->branches);
|
||||
boot::conditional_statements *body = new boot::conditional_statements($2, std::move($4));
|
||||
$$ = new boot::while_statement(boot::make_position(@1), body, std::move($5));
|
||||
}
|
||||
| "while" expression "," IDENTIFIER "do" statements elsif_do_statements "end"
|
||||
{
|
||||
boot::conditional_statements *body = new boot::conditional_statements($2, std::move($6));
|
||||
$$ = new boot::while_statement(boot::make_position(@1), body, std::move($7), $4);
|
||||
}
|
||||
elsif_then_statements:
|
||||
"elsif" expression "then" statements elsif_then_statements
|
||||
{
|
||||
boot::conditional_statements *branch = new boot::conditional_statements($2);
|
||||
std::swap(branch->statements, $4);
|
||||
boot::conditional_statements *branch = new boot::conditional_statements($2, std::move($4));
|
||||
std::swap($5, $$);
|
||||
$$.emplace($$.begin(), branch);
|
||||
}
|
||||
@ -417,13 +421,16 @@ statement:
|
||||
| while_statement { $$ = $1; }
|
||||
| "if" expression "then" statements elsif_then_statements else_statements "end"
|
||||
{
|
||||
auto then = new boot::conditional_statements($2);
|
||||
std::swap($4, then->statements);
|
||||
boot::conditional_statements *then = new boot::conditional_statements($2, std::move($4));
|
||||
auto result = new boot::if_statement(boot::make_position(@1), then, $6);
|
||||
std::swap($5, result->branches);
|
||||
$$ = result;
|
||||
$$ = result;
|
||||
}
|
||||
| return_statement { $$ = $1; }
|
||||
| "break" IDENTIFIER
|
||||
{ $$ = new boot::escape_statement(boot::make_position(@1), boot::escape_direction::end, $2); }
|
||||
| "repeat" IDENTIFIER
|
||||
{ $$ = new boot::escape_statement(boot::make_position(@1), boot::escape_direction::begin, $2); }
|
||||
| call_expression { $$ = $1; }
|
||||
| "defer" statements "end" { $$ = new boot::defer_statement(boot::make_position(@1), std::move($2)); }
|
||||
| "case" expression "of" switch_cases else_statements "end"
|
||||
@ -523,7 +530,7 @@ variable_declarations:
|
||||
variable_part:
|
||||
/* no variable declarations */ {}
|
||||
| "var" variable_declarations { std::swap($$, $2); }
|
||||
constant_definition: identifier_definition "=" expression
|
||||
constant_definition: identifier_definition ":=" expression
|
||||
{
|
||||
$$ = new boot::constant_definition(boot::make_position(@1), $1.first, $1.second, $3);
|
||||
}
|
||||
|
@ -239,6 +239,10 @@ namespace elna::boot
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(escape_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(while_statement *statement)
|
||||
{
|
||||
statement->body().prerequisite().accept(this);
|
||||
|
Reference in New Issue
Block a user