From acc9b94c1f57cb90f837ee26184f12e6252d84e2 Mon Sep 17 00:00:00 2001 From: haxala1r Date: Tue, 30 Sep 2025 21:32:02 +0300 Subject: [PATCH] Fixed an error in double parsing logic --- src/include/lex.hpp | 3 +-- src/lex.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/include/lex.hpp b/src/include/lex.hpp index add0c91..7a4beda 100644 --- a/src/include/lex.hpp +++ b/src/include/lex.hpp @@ -19,9 +19,8 @@ enum TokenType { struct Token { enum TokenType type; std::variant value; - - bool operator==(Token const& other); }; +bool operator==(Token const& one, Token const& other); std::ostream &operator<<(std::ostream &os, Token const &t); class Lexer { diff --git a/src/lex.cpp b/src/lex.cpp index ce4d7a8..b90c08c 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -23,8 +23,8 @@ std::ostream &operator<<(std::ostream &os, Token const &t) { return os; } -bool Token::operator==(Token const& other) { - return this->type == other.type && this->value == other.value; +bool operator==(Token const& one, Token const& other) { + return one.type == other.type && one.value == other.value; } bool ispunct(char c) { @@ -65,9 +65,10 @@ Token Lexer::lexNumOrSym() { // ... this will almost certainly change, won't it? string s = acc.str(); string iterate_over = (s.at(0) == '-') ? s.substr(1) : s; - bool is_number = true; + bool is_number = false; bool dot_seen = false; - for (char c : s) { + for (char c : iterate_over) { + if (c == '.') { if (dot_seen) { is_number = false; @@ -76,14 +77,16 @@ Token Lexer::lexNumOrSym() { dot_seen = true; continue; } - if (!isdigit(c)) { + if (isdigit(c)) { + is_number = true; + } else { is_number = false; break; } } if (is_number && dot_seen) { - if (s == ".") + if (iterate_over == ".") return {TokenType::Symbol, s}; return {TokenType::Double, stod(s)}; } else if (is_number) {