From 9f69b006dde3c3fbe19ed3e0275d3b7348f2aa87 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 15 Mar 2020 18:19:49 +0100 Subject: New lexer --- minicc.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'minicc.cpp') diff --git a/minicc.cpp b/minicc.cpp index 48d2a15..d180517 100644 --- a/minicc.cpp +++ b/minicc.cpp @@ -14,6 +14,8 @@ #include #include +using namespace std::string_literals; + std::vector split(std::string s) { std::vector result; @@ -37,3 +39,18 @@ std::ostream& operator<<(std::ostream& os, const Token& token) { return os << token.type << ": " << token.value << "(" << token.location.line << ":" << token.location.column << ")"; } +void Location::advance(bool newline) +{ + pos++; + if (newline) { + line++; + column = 1; + } else { + column++; + } +} + +std::string Location::toString() +{ + return std::to_string(line) + ":"s + std::to_string(column); +} -- cgit v1.2.3