Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def verification_type(w):
- if w.isdigit():
- return "const"
- elif w.isalpha() and len(w) == 1:
- return "ID"
- else:
- return "operator"
- text = '''if N > 0 THEN ;
- M := M + 1 / N ;
- B := M * N + 3 ;
- if B = 0 THEN write ( N ) ;'''
- word = text.split()
- # print(len(ts))
- hTable = [None for _ in range(36)]
- sTable = list()
- for i in range(len(word)):
- mirror = False
- if len(sTable) > 0:
- for j in range(len(sTable)):
- if word[i] == sTable[j][0]:
- mirror = True
- if mirror == True:
- continue
- hash_ID = hash(word[i]) % 36
- if hTable[hash_ID] is None: # если в ячейке хэш таблицы пусто
- hTable[hash_ID] = len(sTable)
- sTable.append([word[i], verification_type(word[i]), None, hash_ID])
- else:
- latecomer = hTable[hash_ID] # опаздавший ID
- while True:
- if sTable[latecomer][2] is None:
- latecomer_ID = len(sTable) # получаем указатель
- sTable.append([word[i], verification_type(word[i]), None, hash_ID])
- sTable[latecomer][2] = latecomer_ID # записываем указатель в chain
- break
- latecomer = sTable[latecomer][2] # меняем старый указатель на указатель из chain
- print("Таблица символов:")
- for index, m in enumerate(sTable):
- print(index, m)
- print("Хэш таблица:")
- for index, n in enumerate(hTable):
- print(f'{index} {n}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement