From e3936c5fc5b846f90d8cdfc589960c6881caa019 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 27 Mar 2022 11:57:00 -0600 Subject: Lexer funcional --- main.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 main.cpp (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ee376c2 --- /dev/null +++ b/main.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include "include/lexer.hpp" + +using std::string, std::cin, std::cout, std::getline, std::vector, + std::begin, std::end; + +string types[] = {string(1, '+'), string(1, '-'), string(1, '/'), string(1, '*'), + string(1, '^'), "variable", "número", "función", string(1, '('), string(1, ')'), "nil"}; + + +void print_tokens(const vector< Token > &tokens){ + for(auto i = begin(tokens); i != end(tokens); ++i) + { + if(i->type == variable || i->type == number || i->type == function) + cout << "Tipo: " << types[i->type] << "\nValor: " << i->value << '\n'; + else + cout << "Tipo: " << types[i->type] << '\n'; + } +} + +int main(){ + vector< Token > tokens; + string input; + Lexer lexer; + getline(cin, input); + lexer.setText(input); + + while(lexer.getCurrentToken().type != nil) + { + tokens.push_back(lexer.getCurrentToken()); + lexer.nextToken(); + } + print_tokens(tokens); + + return 0; +} -- cgit v1.2.3