-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (30 loc) · 1.09 KB
/
Copy pathmain.py
File metadata and controls
40 lines (30 loc) · 1.09 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
import simplification
class CFG:
Σn: list
Σt: list
P: dict
S: list
def __init__(self, nonTerminals: list, terminals: list, productions: dict, startSymbol: list):
self.Σn = nonTerminals
self.Σt = terminals
self.P = productions
self.S = startSymbol
def print(self, text):
print('\n' + text + '\n')
print('G = ({' + ', '.join(self.Σn) + '}, {' + ', '.join(self.Σt) + '}, P, ' + self.S[0] + ')\n')
print('P:')
for i in range(len(self.Σn)):
print(self.Σn[i] + ' --> ', end='')
print(*(x for x in self.P[self.Σn[i]]), sep='|')
def simplify(self):
self.print('The CFG entered is:')
simplification.removeNonGeneratingSymbols(self)
self.print('The CFG without non generating symbols is:')
simplification.removeNonReachableSymbols(self)
self.print('The CFG simplified is:')
def createCFG():
return simplification.createCFG()
if __name__ == "__main__":
print("Welcome to the CFG Simplification program\n")
CFG = createCFG()
CFG.simplify()