diff --git a/src/include/types.h b/src/include/types.h index a058a72..6a12e8c 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -197,6 +197,7 @@ enum class ErrorType { // Lexing UnknownToken, + IntegerTooLarge, // Parsing EmptyInput, diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 756703c..e3588fa 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -221,9 +221,15 @@ vector tokenize(vector input, int initial_line) { } if (regex_search(str, m, INT_REGEX, regex_constants::match_continuous)) { + int val; + try { val = stoi(m.str()); } + catch (const out_of_range& e) { + throw SyntaxError(ErrorType::IntegerTooLarge, pos); + } + Token token = { .type = TokenType::Litteral, - .data = stoi(m.str()), + .data = val, .pos = pos }; tokens.emplace_back(token);