-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalyseSyntaxique.hpp
137 lines (111 loc) · 3.48 KB
/
AnalyseSyntaxique.hpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#pragma once
/*
* ___ __
* / | ____ ____ _/ /_ __________
* / /| | / __ \/ __ `/ / / / / ___/ _ \
* / ___ |/ / / / /_/ / / /_/ (__ ) __/
* /_/ |_/_/ /_/\__,_/_/\__, /____/\___/
* /____/
* __ _
* _______ ______ / /_____ __ __(_)___ ___ _____
* / ___/ / / / __ \/ __/ __ `/ |/_/ / __ `/ / / / _ \
* (__ ) /_/ / / / / /_/ /_/ /> </ / /_/ / /_/ / __/
* /____/\__, /_/ /_/\__/\__,_/_/|_/_/\__, /\__,_/\___/
* /____/ /_/
*
*
* https://github.com/Idriss975/Automate-header
*
*/
#include <exception>
#include <string>
#include <stdexcept>
#include <vector>
#include <array>
#include <unordered_set>
class InvalidVariable: public std::runtime_error
{
public:
InvalidVariable(const char* m) : std::runtime_error(m)
{}
};
/// @brief Abstract class for Variable_terminale & Variable_non_terminale
class Variable_Lexicale
{
public:
char val;
};
class Variable_terminale : public Variable_Lexicale
{
public:
Variable_terminale() = default;
Variable_terminale(char valeur);
std::string toString() const;
bool operator ==(const Variable_terminale & Vt) const;
struct HashFunction
{
size_t operator()(const Variable_terminale& Vt) const
{
return std::hash<int>()(Vt.val);
}
};
};
class Regle;
class Variable_non_terminale : public Variable_Lexicale
{
public:
Regle* Right;
Variable_non_terminale() = default;
Variable_non_terminale(char valeur);
Variable_non_terminale(char valeur, Regle* R); // throws InvalidVariable
std::string toString() const;
bool operator ==(const Variable_non_terminale & Vn) const;
};
class Regle
{
private:
bool is_nullable;
public:
Variable_non_terminale Partie_gauche;
std::vector<std::vector<Variable_Lexicale>> Partie_droite;
Regle() = default;
Regle(Variable_non_terminale left, std::vector<std::vector<Variable_Lexicale>> right, bool is_null=false);
Regle(char left, std::vector<std::string> right, bool is_null=false);
bool Recursive_aGauche() const;
void Eliminer_Recursivite_aGauche();
bool Factorisation_aGauche() const;
void Eliminer_Factorisation_aGauche();
bool Nullable() const;
std::unordered_set<Variable_terminale> Premier() const;
void Ajouter_OU(std::vector<Variable_Lexicale> r);
std::string toString() const;
};
/*
template<size_t NB_Vn, size_t NB_Vt>
class Tableau_analyse
{
public:
std::array<Variable_non_terminale, NB_Vn> Vn;
std::array<Variable_terminale, NB_Vt> Vt;
Tableau_analyse() = default;
};
template<size_t NB_Vn, size_t NB_Vt>
class Grammaire
{
public:
std::array<Regle, NB_Vn> Regles;
std::array<Variable_non_terminale, NB_Vn> Vn;
std::array<Variable_terminale, NB_Vt> Vt;
Variable_non_terminale* Axiome;
Grammaire() = default;
Grammaire(std::array<Regle, NB_Vn> R, char Axiome);
Grammaire(std::array<Regle, NB_Vn> R, Variable_non_terminale* Axiome);
bool Recursive_aGauche() const;
void Eliminer_Recursivite_aGauche();
bool Factorisation_aGauche() const;
void Eliminer_Factorisation_aGauche() const;
std::unordered_set<Variable_terminale> Suivant(Variable_non_terminale Vt) const;
Tableau_analyse<NB_Vn, NB_Vt> Generer_Tableau_analyse() const:
std::string toString() const;
};
*/