-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.hpp
More file actions
76 lines (68 loc) · 2.71 KB
/
Copy pathparser.hpp
File metadata and controls
76 lines (68 loc) · 2.71 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include "lexer.hpp"
#include "formulas_server.hpp"
#include <utility>
#include <algorithm>
#include <string>
#include <cstdlib>
namespace Dima
{
class Node
{
private:
std::vector<const Node*> _chPtr{}; //потомки вершины
enum TokenType _mType{WHITESPACE}; //тип вершины дерева
bool _mTerm; //1, если терминал
bool _vTerm{0}; //1, если терминал посещен
std::string _mText{""};
public:
Node(int isTerm, enum TokenType type);
Node(int isTerm, std::string text, enum TokenType type);
Node();
void setType(enum TokenType newType);
void setText(std::string newText);
void setMTerm(bool mTerm);
void setVTerm(bool vTerm);
enum TokenType getType() const;
std::string getText() const;
bool getMTerm() const;
bool getVTerm() const;
std::vector<const Node*> getChildren() const; //получить потомков вершины
void addChild(const Node* addedNode); //добавить потомка
};
class parseTree
{
private:
Node* _root; //корень дерева
Node* _upperNode; //текущий раскрываемый нетерминал
std::vector<Token> _Line; //разбираемая последовательность терминалов
Kirill::DNF _dnf; //ДНФ, собранная из дерева
Kirill::Conjunct _conjunct;
Kirill::Greater_predicate* _grPredicate;
Kirill::Equality_predicate* _eqPredicate;
std::vector<std::pair<mpz_class, int>> _leftPolynomCoefs;
std::vector<std::pair<mpz_class, int>> _rightPolynomCoefs;
std::vector<std::pair<mpz_class, int>> _resultCoefsTMP;
std::vector<mpz_class> _resultCoefs;
bool _negFlag{false};
bool _degreeFlag{false};
int _degree{0};
mpz_class _curCoefficient{1};
bool _leftFlag{false}; //если левый многочлен записан
void _merge(std::vector<std::pair<mpz_class, int>> a, std::vector<std::pair<mpz_class, int>> b);
void _getUpperNode(const Node* toNode); //поиск верхнего в стеке нетерминала
void _addNode(const Node* addedNode); //замена раскрытого нетерминала
const int _ifMatched(Node* nTerm, Token Term); //анализ LL-таблицы
void _makeDNF(const Node* fromNode);
void _makeConjunct(const Node* fromNode);
void _makePredicate(const Node* fromNode);
void _deleteFromNode(const Node* fromNode);
public:
parseTree(const std::vector<Token>& Line);
~parseTree();
void getUpperNode(); //обновление текущего вызываемого нетерминала
void parse(); //парсинг вектора токенов
void makeDNF();
Kirill::DNF getDNF();
};
}