-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathputo_parser_predictivo.py
41 lines (37 loc) · 1.02 KB
/
puto_parser_predictivo.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
from gramaticas import gramaticaSTR
from lexer import lexer
from sd import SD
def principal(lista, gramatica):
sd = SD
error = False
t = 0
def P(noTerminal):
nonlocal error
error = False
for i, derivacion in enumerate(gramatica['P'][noTerminal]):
def procesar(derivacion):
nonlocal t
nonlocal error
for xj in derivacion:
if xj in gramatica['T']:
if lista[t] == xj:
t += 1
else:
error = True
break
elif xj in gramatica['N']:
P(xj)
if error:
break
if lista[t] in sd[noTerminal]:
procesar(derivacion)
P(gramatica['S'])
if not error and lista[t] == '#':
print('Cadena aceptada')
else:
print('Cadena rechazada')
cadena = 'si vgAuxi==7, entonces vgAuxi igual 1, sino leer libro. FinSi.'
#print(lexer(cadena))
lista = [token[1] for token in lexer(cadena)]
#print(lista)
principal(lista, gramaticaSTR)