summaryrefslogtreecommitdiff
path: root/include/parser.hpp
blob: 3f0032bfaf5d4835a41f71e44824c560df6d3a65 (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
/* PIA - Lenguajes Modernos de Programación
 * FACULTAD DE CIENCIAS FÍSICO MATEMÁTICAS
 * Luis Sebastián Martínez Vega - LCC */

#include <string>
#include <vector>
#include "expressions.hpp"
#include "lexer.hpp"
#ifndef PARSER_H
#define PARSER_H

class Parser{
private:
  std::string text;
  Lexer tokenizer;
  std::vector<Expression *> tree_stack;
  Token var{nil, "{}"};
  void panic();
  Expression *popStack();
  Expression *newTree(token_type type);
  void setText(std::string text);
  void parseExpr();
  void parsePrimeExpr();
  void parseTerm();
  void parsePrimeTerm();
  void parsePower();
  void parsePrimePower();
  void parseFactor();
  bool checkToken(); // Checa el token actual del lexer.
public:
  Expression *parse(std::string expr);
};

#endif /* PARSER_H */