diff --git a/examples/parser-test.sp b/examples/parser-test.sp index 13da2ef..63d6e67 100644 --- a/examples/parser-test.sp +++ b/examples/parser-test.sp @@ -1 +1 @@ -2+2*6+ +2 2 6+ diff --git a/src/Parser.cpp b/src/Parser.cpp index d15f482..01ca4d9 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -17,6 +17,10 @@ std::shared_ptr Parser::parse() advance(); auto result = expr(); if (result.is_error()) result.ethrow(); + if (current_token->tk_type != TT_EOF) + { + Err("expected *, /, + or -",current_token).ethrow(); + } return result.get(); } diff --git a/src/Result.h b/src/Result.h index c61f7f8..eae3f82 100644 --- a/src/Result.h +++ b/src/Result.h @@ -16,6 +16,10 @@ template class Result { Error::throw_error(m_token->loc, m_token->line(), m_error); } + Token* token() + { + return m_token; + } std::shared_ptr get() { return m_result;