From 251a9af5e8c4976373b71935457d1ce17c6888a1 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 31 Aug 2016 18:59:42 +0000 Subject: Add token class --- parser.cpp | 9 ++++++--- token.cpp | 7 +++++++ token.h | 11 +++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 token.cpp create mode 100644 token.h diff --git a/parser.cpp b/parser.cpp index 91e4067..76da588 100644 --- a/parser.cpp +++ b/parser.cpp @@ -1,9 +1,10 @@ #include "parser.h" #include #include +#include "token.h" Parser::Parser(std::string& input) { - std::vector result; + std::vector result; bool isString = false; std::string tmp; @@ -14,7 +15,8 @@ Parser::Parser(std::string& input) { } if (c == '"' && isString) { - result.push_back(tmp); + Token token(tmp, true); + result.push_back(token); tmp = ""; isString = false; continue; @@ -22,7 +24,8 @@ Parser::Parser(std::string& input) { if (!isString) { std::string parsed(1, c); - result.push_back(parsed); + Token token(parsed, false); + result.push_back(token); } else { tmp += c; diff --git a/token.cpp b/token.cpp new file mode 100644 index 0000000..560f89e --- /dev/null +++ b/token.cpp @@ -0,0 +1,7 @@ +#include "token.h" + +Token::Token(std::string& lexeme, bool isString) : + m_lexeme(lexeme), m_isString(isString) { + +} + diff --git a/token.h b/token.h new file mode 100644 index 0000000..b6ad24d --- /dev/null +++ b/token.h @@ -0,0 +1,11 @@ +#pragma once +#include + +class Token { + private: + std::string m_lexeme; + bool m_isString; + + public: + Token(std::string& lexeme, bool isString); +}; -- cgit v1.3