Fix tokenizer int overflow
This commit is contained in:
parent
f7af17c899
commit
965d834d22
@ -197,6 +197,7 @@ enum class ErrorType {
|
|||||||
|
|
||||||
// Lexing
|
// Lexing
|
||||||
UnknownToken,
|
UnknownToken,
|
||||||
|
IntegerTooLarge,
|
||||||
|
|
||||||
// Parsing
|
// Parsing
|
||||||
EmptyInput,
|
EmptyInput,
|
||||||
|
@ -221,9 +221,15 @@ vector<Token> tokenize(vector<string> input, int initial_line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (regex_search(str, m, INT_REGEX, regex_constants::match_continuous)) {
|
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 = {
|
Token token = {
|
||||||
.type = TokenType::Litteral,
|
.type = TokenType::Litteral,
|
||||||
.data = stoi(m.str()),
|
.data = val,
|
||||||
.pos = pos
|
.pos = pos
|
||||||
};
|
};
|
||||||
tokens.emplace_back(token);
|
tokens.emplace_back(token);
|
||||||
|
Loading…
Reference in New Issue
Block a user