diff options
author | HombreLaser <sebastian-440@live.com> | 2022-04-02 11:53:03 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-04-02 11:53:03 -0600 |
commit | 4a8400c2846a0db0778817e48da6c0f20849471f (patch) | |
tree | 9c46205ea9ca5a8fbe9d8b590c24172be911615a | |
parent | e3936c5fc5b846f90d8cdfc589960c6881caa019 (diff) |
Todo listo para el parser
-rw-r--r-- | main.cpp | 37 | ||||
-rw-r--r-- | makefile | 4 |
2 files changed, 15 insertions, 26 deletions
@@ -1,39 +1,28 @@ #include <iterator> +#include <ostream> #include <string> #include <vector> #include <iostream> -#include "include/lexer.hpp" +#include "include/parser.hpp" +#include "include/exceptions.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'; - } -} + std::begin, std::end, std::endl; int main(){ - vector< Token > tokens; string input; - Lexer lexer; + Parser parser; + getline(cin, input); - lexer.setText(input); - while(lexer.getCurrentToken().type != nil) + try { - tokens.push_back(lexer.getCurrentToken()); - lexer.nextToken(); - } - print_tokens(tokens); + parser.parse(input); + cout << "Todo correcto." << endl; + }catch(ParserException e) + { + cout << e.showMsg() << endl; + } return 0; } @@ -1,7 +1,7 @@ CC=g++ CFLAGS= -std=gnu++17 -g -DEPS = include/lexer.hpp include/exceptions.hpp -OBJ = lexer.o exceptions.o main.o +DEPS = include/lexer.hpp include/exceptions.hpp include/parser.hpp +OBJ = lexer.o exceptions.o parser.o main.o %.o : %.cpp $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) |