Support compound statements

This commit is contained in:
2024-03-11 10:43:26 +01:00
parent 2c396ece17
commit 25657ac36d
12 changed files with 242 additions and 86 deletions

View File

@ -175,6 +175,11 @@ namespace elna::source
return m_statements;
}
void assignment_statement::accept(parser_visitor *visitor)
{
visitor->visit(this);
}
parser::parser(const std::vector<token>& tokens)
: tokens(tokens.cbegin()), end(tokens.cend())
{
@ -323,16 +328,25 @@ namespace elna::source
auto result = std::make_unique<compound_statement>();
std::unique_ptr<statement> next_statement;
do
while ((next_statement = parse_statement()) != nullptr)
{
if ((next_statement = parse_statement()) == nullptr)
{
return nullptr;
}
result->statements().push_back(std::move(next_statement));
if (tokens->of() == token::type::semicolon)
{
++tokens;
}
else if (tokens->of() == token::type::end)
{
++tokens;
break;
}
else
{
errors.push_back(std::make_unique<unexpected_token>(*tokens));
break;
}
}
while (tokens->of() != token::type::end);
++tokens;
return result;
}