Fix tokenizer int overflow

This commit is contained in:
ala89 2023-12-15 14:46:24 +01:00
parent f7af17c899
commit 965d834d22
2 changed files with 8 additions and 1 deletions

View File

@ -197,6 +197,7 @@ enum class ErrorType {
// Lexing
UnknownToken,
IntegerTooLarge,
// Parsing
EmptyInput,

View File

@ -221,9 +221,15 @@ vector<Token> tokenize(vector<string> 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);