Support compound statements

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

View File

@ -58,6 +58,12 @@ namespace elna::source
return *this;
}
text_iterator text_iterator::operator+(std::size_t step)
{
auto result = *this;
return ++result;
}
bool text_iterator::operator==(const text_iterator& that) const noexcept
{
return this->m_buffer == that.m_buffer;
@ -309,6 +315,11 @@ namespace elna::source
tokens.emplace_back(token::type::factor_operator, _operator.c_str(), iterator.position());
}
else if (*iterator == ':' && iterator + 1 != text_end && *(iterator + 1) == '=')
{
tokens.emplace_back(token::type::assignment, iterator.position());
++iterator;
}
else
{
return source_result(unexpected_character{ std::string{ *iterator }, iterator.position() });

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;
}

View File

@ -82,6 +82,10 @@ namespace elna::source
{
}
void name_analysis_visitor::visit(assignment_statement *statement)
{
}
void name_analysis_visitor::visit(block *block)
{
}