diff options
author | HombreLaser <sebastian-440@live.com> | 2022-03-27 11:57:00 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-03-27 11:57:00 -0600 |
commit | e3936c5fc5b846f90d8cdfc589960c6881caa019 (patch) | |
tree | e198e538fb6a1af8925bbf9dc1351dc24e5db589 /main.cpp | |
parent | 07885de508b71ef4c4097f14cc5edc9e288b0631 (diff) |
Lexer funcional
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
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 <iterator> +#include <string> +#include <vector> +#include <iostream> +#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; +} |