diff --git a/src/include/lex.hpp b/src/include/lex.hpp index 7914cdc..dd13749 100644 --- a/src/include/lex.hpp +++ b/src/include/lex.hpp @@ -40,3 +40,5 @@ public: std::vector collect(); }; +// when you don't want to construct the object +std::vector lex(std::string); diff --git a/src/lex.cpp b/src/lex.cpp index fd47c8a..5b6b6f2 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -135,5 +135,19 @@ Token Lexer::next() { } } +vector Lexer::collect() { + vector v; + while (true) { + Token t = next(); + if (t.type == TokenType::End) + break; + v.push_back(t); + } + return v; +} +std::vector lex(std::string s) { + Lexer l(s); + return l.collect(); +} diff --git a/src/main.cpp b/src/main.cpp index cc53e1a..5501e6c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,17 @@ #include #include -#include +#include using namespace std; int main() { string s; - cin >> s; + getline(cin, s); + cout << s << endl; - Lexer l(s); - cout << l.next() << endl; + for (auto t : lex(s)) { + cout << t << " "; + } + cout << endl; return 0; } \ No newline at end of file