aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2016-08-31 18:59:42 +0000
committerJan Tuomi <jans.tuomi@gmail.com>2016-08-31 18:59:42 +0000
commit251a9af5e8c4976373b71935457d1ce17c6888a1 (patch)
tree33313df7f059bbf3a825d83d7ef0273b2ec012c2
parentc59f10a0b0f58840c02327fc602a681c5410b212 (diff)
Add token class
-rw-r--r--parser.cpp9
-rw-r--r--token.cpp7
-rw-r--r--token.h11
3 files changed, 24 insertions, 3 deletions
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 <string>
#include <vector>
+#include "token.h"
Parser::Parser(std::string& input) {
- std::vector<std::string> result;
+ std::vector<Token> 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 <string>
+
+class Token {
+ private:
+ std::string m_lexeme;
+ bool m_isString;
+
+ public:
+ Token(std::string& lexeme, bool isString);
+};