Added error on unfinished parsing

This commit is contained in:
apio 2022-08-03 15:22:13 +00:00
parent e0661f9f8f
commit 3289ae0148
3 changed files with 9 additions and 1 deletions

View File

@ -1 +1 @@
2+2*6+ 2 2 6+

View File

@ -17,6 +17,10 @@ std::shared_ptr<ASTNode> Parser::parse()
advance(); advance();
auto result = expr(); auto result = expr();
if (result.is_error()) result.ethrow(); if (result.is_error()) result.ethrow();
if (current_token->tk_type != TT_EOF)
{
Err<ExprNode>("expected *, /, + or -",current_token).ethrow();
}
return result.get(); return result.get();
} }

View File

@ -16,6 +16,10 @@ template<typename T> class Result
{ {
Error::throw_error(m_token->loc, m_token->line(), m_error); Error::throw_error(m_token->loc, m_token->line(), m_error);
} }
Token* token()
{
return m_token;
}
std::shared_ptr<T> get() std::shared_ptr<T> get()
{ {
return m_result; return m_result;