-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (62 loc) · 1.85 KB
/
main.py
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
import re
from analyser import Analyser
from grammar import Grammar
class UI:
'''
Initializare UI cu analyser
'''
def __init__(self, grammar):
self.grammar = grammar
'''
Printare meniu ui
'''
def printMenu(self):
print('x => Iesire')
print('1 => Multimea neterminalelor')
print('2 => Multimea terminalelor')
print('3 => Multimea regulilor de productie')
print('4 => Multimea regulilor de productie pentru un anumit terminal')
print('5 => Verifica o secventa de intrare')
'''
Printare lista pe ecran
'''
def printList(self, adict):
for key in adict.keys():
multi_value = adict[key]
for value in multi_value:
print(key, '->', value)
'''
Rulare meniu ui
'''
def run(self):
s = ''
while True:
self.printMenu()
s = input()
if re.search('^[x]$', s):
break
try:
print()
if s =='1':
var = grammar.get_neterminals()
print(var)
if s =='2':
var = grammar.get_terminals()
print(var)
if s =='3':
var = grammar.get_productions()
self.printList(var)
if s =='4':
non = input('terminal >')
var = grammar.get_productions_for_terminal(non)
for x in var:
print(x)
if s =='5':
non = input('numele fisierului >')
var = grammar.accepts_file(non)
print(var)
print()
except Exception as e:
print(e)
grammar = Grammar()
UI(grammar).run()