-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_print.py
More file actions
53 lines (45 loc) · 1.48 KB
/
format_print.py
File metadata and controls
53 lines (45 loc) · 1.48 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
unicode = { 'Q' : '\U0001D4AC', 'Sigma' : '\u2211', 'delta' : '\u03b4', 'q0' : 'q\u2080', 'F' : '\U0001D439', 'R' : '\U0001D445', 'cap' : '\u2229', 'empty' : '\u2205'}
''' Print Formatted Transitions
formats delta
'''
def transitions(label, delta, alphabet):
# delta = {state:(accepting,{symbol:state_to})}
if(len(list(delta.keys())[0]) == 2):
print('\t', label, ' =\t |', sep='', end='')
for c in alphabet:
print('| ', c, end=' ')
print('|\n', end='\t\t====')
for c in alphabet:
print('=====', end='')
print('=')
for state, info in delta.items():
print('\t\t', state, sep='', end=' |')
for symbol in info[1]:
print('|', info[1][symbol], end=' ')
print('|')
if(len(list(delta.keys())[0]) == 4):
print('\t', label, ' =\t\t |', sep='', end='')
for c in alphabet:
print('| ', c, end=' ')
print('|\n', end='\t\t======')
for c in alphabet:
print('=======', end='')
print('=')
for state, info in delta.items():
print('\t\t', state, sep='', end=' |')
for symbol in info[1]:
print('|', info[1][symbol], end=' ')
print('|')
''' Print Formatted
formats lists
'''
def dfa_item(label, items):
if len(items) == 0:
print('\t', label, ' = ', unicode['empty'], sep='')
else:
print('\t', label, ' = {', sep='', end='')
for i in range(0,len(items)):
if(i < len(items)-1):
print(items[i], end=', ')
else:
print(items[i], '}', sep='')