This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRG_Grammar.h
78 lines (62 loc) · 1.92 KB
/
RG_Grammar.h
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
/**
* @file RG_Grammar.h
* @author Yacine Smaoui, Florian Hemmelgarn
*
* @brief Definition of the Grammar class
*/
#ifndef GRAMMAR_H_
#define GRAMMAR_H_
#include <iostream>
#include "RG_DynArray.h"
#include "RG_Production.h"
#include "FSA_FiniteStateAutomaton.hpp"
#include "RE_RegularExpression.hpp"
using namespace std;
#define EMPTY_STRING "<epsilon>"
/**
* @class Grammar
* @brief Represents a Grammar
*
* (the fact that the Grammar is a Regular Grammar or not is checked (if wanted) after reading (or creating )
* with the method Grammar::checkIfRegular()
*
* A Grammar is defined through its Terminals, Non-Terminals and the Start Symbol.
* For this purpose, the chosen container class is a Dynamic Array defined in DynArray.h
*
* see checkIfRegular() for more information about a REGULAR Grammar
*/
class Grammar
{
public:
Grammar();
~Grammar();
private:
/** a Dynamic array container to store the Terminals of the Grammar */
DynArray<string> Terminals;
/** a Dynamic array container to store the NonTerminals of the Grammar */
DynArray<string> NonTerminals;
/** a dynamic array container to store the Productions of the Grammar */
DynArray<Production*> Productions;
/** the Start symbol of the Grammar */
string StartSymbol;
/** 1 if Grammar is Regular */
int isRegular;
public:
void addProduction(Production* prod);
void setStartSymbol(string s);
void addTerminal (string s);
void addNonTerminal(string s);
void processGrammarProductions();
DynArray<string> getTerminals();
DynArray<string> getNonTerminals();
string getStartSymbol();
DynArray<Production*> getProductions();
int getNumberOfProductions();
Production* getProduction(int index);
int isStartSymbol(string symbol);
void checkIfRegular();
void initConvert();
FiniteStateAutomaton* convertToFSA();
//RegularExpression *convertToRE();
};
#endif /* GRAMMAR_H_ */