From 3289ae0148480a18bf4682f37d941374d2f29e5d Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 3 Aug 2022 15:22:13 +0000 Subject: [PATCH] Added error on unfinished parsing --- examples/parser-test.sp | 2 +- src/Parser.cpp | 4 ++++ src/Result.h | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) 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;