From 190c016f4a55fe4b9d5687f02809b3ce18cbcca9 Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Tue, 11 Aug 2026 18:31:34 +0000 Subject: [PATCH] fix(translate): simplify float literal recognition --- lib/Translation/ForthToMLIR/ForthToMLIR.cpp | 23 +++++---------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/Translation/ForthToMLIR/ForthToMLIR.cpp b/lib/Translation/ForthToMLIR/ForthToMLIR.cpp index fd0c860..fd568d7 100644 --- a/lib/Translation/ForthToMLIR/ForthToMLIR.cpp +++ b/lib/Translation/ForthToMLIR/ForthToMLIR.cpp @@ -137,20 +137,8 @@ bool ForthLexer::isFloat(const std::string &str) const { if (str.empty()) return false; - // Try to parse as a double. A valid float must contain a '.' or 'e'/'E'. - bool hasDotOrExp = false; - for (char c : str) { - if (c == '.' || c == 'e' || c == 'E') { - hasDotOrExp = true; - break; - } - } - if (!hasDotOrExp) - return false; - - char *end = nullptr; - std::strtod(str.c_str(), &end); - return end == str.c_str() + str.size(); + double value; + return llvm::to_float(str, value); } Token ForthLexer::nextToken() { @@ -179,11 +167,10 @@ Token ForthLexer::nextToken() { std::string text(tokenStart, curPtr - tokenStart); Token::Kind kind; - if (isFloat(text)) { - kind = Token::Kind::Float; - // Don't uppercase float tokens (preserve original text for strtod) - } else if (isNumber(text)) { + if (isNumber(text)) { kind = Token::Kind::Number; + } else if (isFloat(text)) { + kind = Token::Kind::Float; } else { kind = Token::Kind::Word; text = toUpperCase(text);