summaryrefslogtreecommitdiff
path: root/main.cpp
blob: ee376c2edbef19166fff804c5cb17f2f883f8b11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
}