-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSintactico.py
820 lines (673 loc) · 25.4 KB
/
Sintactico.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
# ┌----------- GRAMÁTICA EBNF PARA NUESTRO LENGUAJE ------------┐
# | Programa -> main { lista-declaración lista-sentencia } |
# | lista-declaración -> { declaración ; } |
# | declaración -> tipo lista-variables |
# | tipo -> int | real | boolean |
# | lista-variables -> id [ , id ] |
# | lista-sentencia -> { sentencia } |
# | sentencia -> sent-if | sent-while | sent-repeat | sent-cin | sent-cout | sentencia | asignación
# | sent-if -> if ( expresión ) then bloque [ else bloque ] |
# | sent-while -> while ( expresión ) bloque |
# | sent-repeat -> repeat bloque until ( expresión ) ; |
# | sent-cin -> cin identificador ; |
# | sent-cout -> cout expresión ; |
# | bloque -> { lista-sentencia } |
# | asignación -> identificador := expresión ; |
# | expresión -> exp [ relación exp ] |
# | relación -> <= | < | > | >= | == | != |
# | exp -> term { opsuma term } |
# | opsuma -> + | - |
# | termino -> factor { opmult factor } |
# | opmult -> * | / |
# | factor -> ( expresión ) | numero | identificador |
# └--------------------------------------------------------------┘
#
# Los "Primeros" y "Siguientes" están dados al final de este archivo. Para recuperación de Errores.
from TreeNode import *
import sys
import pickle
tokens = [] # Todos los tokens salidos del Léxico
token = None # Token actual
contador = 0 # Para recorrer los tokens
# Leer el archivo de entrada como argumento (En conjunto con IDE(Java)):
filepath = sys.argv[1]
output = open(filepath, "r")
# Para leer desde txt:
# output = open("Tokens.txt", "r")
for line in output:
linea, columna, tipo, lexema = line.split(" ")
tok = Token(linea, columna, tipo, lexema[:-1]) # Substring hasta -1 porque agregaba "\n"
if tok.tipo != "TKN_ERROR":
tokens.append(tok)
def match(expected):
pass
global token
if expected == token.tipo:
token = getToken()
else:
print("Syntax error, unexpected '" + token.lexema + "' was expected: " + expected +
" before column " + token.columna + " at line " + token.linea)
output.write("Syntax error, unexpected '" + token.lexema + "' was expected: " + expected +
" before column " + token.columna + " at line " + token.linea + "\n")
def getToken():
pass
global contador, tokens
if contador < len(tokens):
tok = tokens[contador]
contador += 1
return tok
else:
tok = tokens[contador - 1]
linea = tok.linea
columna = int(tok.columna) + 1
tok = Token(linea, str(columna), "TKN_EOF", "EOF")
return tok # End of file
def scanto(synchset):
global token
while True:
if token.tipo == "TKN_EOF":
break
elif not token.tipo in synchset:
token = getToken()
else:
break
return
def checkinput(firstset, followset):
global token
if not token.tipo in firstset:
print("Syntax error, unexpected '" + token.lexema + "' before column " + token.columna + " at line "
+ token.linea)
output.write("Syntax error, unexpected '" + token.lexema + "' before column " + token.columna + " at line "
+ token.linea + "\n")
scanto(firstset + followset)
return
def newStmtNode(kind):
pass
global token
t = TreeNode()
t.token = token
# No recuerdo porqué 3 veces, pero atribuimos el tipo de nodo > Statement y el subtipo > IfK, CoutK, DeclK...
i = 0
while i < 3:
t.nodeKind = NodeKind.StmtK
t.kind = kind
i += 1
return t
def newExpNode(ExpKind):
pass
global token
t = TreeNode()
t.token = token
# Lo mismo que en newStmtNode
i = 0
while i < 3:
t.nodeKind = NodeKind.ExpK
t.kind = ExpKind
i += 1
return t
# --------------- Declaración de funciones ---------------------
def main():
pass
global token, tokens
t = TreeNode()
if token.tipo == "TKN_EOF":
print("Empty file")
else:
firstset = ["TKN_MAIN"]
synchset = ["TKN_EOF"]
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = newStmtNode(StmtKind.MainK)
match("TKN_MAIN")
match("TKN_LBRACE")
if t is not None:
t.branch[0] = stmt_sequence(["TKN_RBRACE"])
try:
match("TKN_RBRACE")
except:
# tokAux = tokens[contador-1]
# longitud = (float(tokAux.columna) + len(tokAux.lexema))-1
# print("Syntax error, was expected '}' after column " + longitud + " at line " + tokAux.linea)
# output.write("Syntax error, was expected '}' after column " + tokAux.columna + " at line " +
# tokAux.linea + "\n")
pass
return t
def stmt_sequence(synchset):
pass
global token
t = TreeNode()
t = statement(synchset)
p = t
if not token.tipo in synchset:
while (token.tipo != "TKN_RBRACE") & (token.tipo != "TKN_EOF"):
q = statement(synchset)
if q is not None:
if t is None:
p = q
t = p
else:
p.sibling.append(q)
p = q
return t
def statement(synchset):
pass
global token
t = TreeNode()
firstset = ["TKN_IF", "TKN_WHILE", "TKN_REPEAT", "TKN_CIN", "TKN_COUT", "TKN_LBRACE", "TKN_ID", "TKN_INT",
"TKN_REAL",
"TKN_BOOLEAN"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = TreeNode()
if token.tipo == "TKN_ID":
t = assign_stmt(synchset + ["TKN_IF", "TKN_WHILE", "TKN_REPEAT", "TKN_CIN", "TKN_COUT", "TKN_LBRACE",
"TKN_INT", "TKN_REAL", "TKN_BOOLEAN"])
elif token.tipo == "TKN_IF":
t = if_stmt(synchset)
elif token.tipo == "TKN_CIN":
t = cin_stmt(synchset)
elif token.tipo == "TKN_COUT":
t = cout_stmt(synchset)
elif (token.tipo == "TKN_REAL") | (token.tipo == "TKN_INT") | (token.tipo == "TKN_BOOLEAN"):
t = declaration_stmt(synchset)
elif token.tipo == "TKN_LBRACE":
t = block(synchset)
elif token.tipo == "TKN_WHILE":
t = while_stmt(synchset)
elif token.tipo == "TKN_REPEAT":
t = repeat_stmt(synchset)
# checkinput(synchset, firstset)
return t
def block(synchset):
pass
global token
firstset = ["TKN_LBRACE", "TKN_IF", "TKN_WHILE", "TKN_REPEAT", "TKN_CIN", "TKN_COUT", "TKN_ID"]
synchset += []
checkinput(firstset, synchset)
t = TreeNode()
if not token.tipo in synchset:
match("TKN_LBRACE")
t = stmt_sequence(synchset)
match("TKN_RBRACE")
# checkinput(synchset, firstset)
return t
def declaration_stmt(synchset):
pass
global token
firstset = ["TKN_INT", "TKN_REAL", "TKN_BOOLEAN"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = newStmtNode(StmtKind.DeclK)
tipo = token.tipo
match(token.tipo)
# Mejoramos el tipo de atributo que será y valor
val = 0
if tipo == "TKN_INT":
tipo = "int"
elif tipo == "TKN_REAL":
tipo = "real"
val = 0.0
elif tipo == "TKN_BOOLEAN":
tipo = "boolean"
w = newStmtNode(StmtKind.AssignK)
t.branch[0] = w
flag = False
while token.tipo == "TKN_ID": # Posterior a la Declaracion debe seguirle un ID por lo menos
q = None # Auxiliar de Nodo
p = newStmtNode(StmtKind.AssignK) # Subnodo de tipo assignación
i = 0 # Para iterar los hijos
e = t.branch[0] # e = al hijo[0]
while e is not None: # Vamos a profundizar hijo-hermano-hijo-hermano... hasta que ya no haya hermanos
q = e # Usamos el otro aux2 = aux
try:
e = e.sibling[i]
except:
e = None # Ya no hay hermanos, aquí es donde colocaremos el nuevo TKN_ID como hermano siguiente
# Si solo es un TKN_ID, atribuimos a q. Si son más, atribuimos a p y lo enlazamos con q
if not flag:
q.attr.name = token.lexema
q.attr.tipe = tipo
q.attr.val = val
else:
p.attr.name = token.lexema
p.attr.tipe = tipo
p.attr.val = val
q.sibling.append(p)
match("TKN_ID")
if token.tipo == "TKN_COMMA": # Es error si pone dos o más ID's sin coma
match("TKN_COMMA")
else:
break
flag = True
# checkinput(synchset, firstset)
match("TKN_SEMICOLON")
return t
def if_stmt(synchset):
pass
global token
firstset = ["TKN_IF"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = newStmtNode(StmtKind.IfK)
match("TKN_IF")
if t is not None:
match("TKN_LPAREN")
t.branch[0] = expresion(["TKN_SEMICOLON", "TKN_RPAREN", "TKN_THEN"])
match("TKN_RPAREN")
if token.tipo == "TKN_THEN":
t.sibling.append(newStmtNode(StmtKind.ThenK))
else:
tAux = token
token = Token(token.linea, token.columna, "TKN_THEN", "then")
t.sibling.append(newStmtNode(StmtKind.ThenK))
token = tAux
match("TKN_THEN")
if t is not None:
t.sibling[0].branch[0] = block(["TKN_ELSE", "TKN_RBRACE"])
if token.lexema == "else":
t.sibling.append(newStmtNode(StmtKind.ElseK))
match("TKN_ELSE")
if t is not None:
t.sibling[1].branch[0] = block(["TKN_RBRACE"])
# t.sibling.append(statement(synchset))
# checkinput(synchset, firstset)
return t
def while_stmt(synchset):
pass
global token
firstset = ["TKN_WHILE"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = newStmtNode(StmtKind.WhileK)
match("TKN_WHILE")
if t is not None:
match("TKN_LPAREN")
t.branch[0] = expresion(["TKN_SEMICOLON", "TKN_RPAREN"])
match("TKN_RPAREN")
if t is not None:
t.branch[1] = block(["TKN_RBRACE"])
# checkinput(synchset, firstset)
return t
def repeat_stmt(synchset):
pass
global token
firstset = ["TKN_REPEAT"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = newStmtNode(StmtKind.RepeatK)
match("TKN_REPEAT")
if t is not None:
t.branch[0] = block(["TKN_UNTIL", "TKN_RBRACE"])
if token.tipo == "TKN_UNTIL":
t.sibling.append(newStmtNode(StmtKind.UntilK))
else:
tAux = token
token = Token(token.linea, token.columna, "TKN_UNTIL", "until")
t.sibling.append(newStmtNode(StmtKind.UntilK))
token = tAux
match("TKN_UNTIL")
if t is not None:
match("TKN_LPAREN")
t.sibling[0].branch[0] = expresion(["TKN_SEMICOLON", "TKN_RPAREN"])
match("TKN_RPAREN")
match("TKN_SEMICOLON")
# checkinput(synchset, firstset)
return t
def assign_stmt(synchset):
pass
global token, tokens, contador
t = TreeNode()
firstset = ["TKN_ID"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
q = newStmtNode(StmtKind.AssignK)
if q is not None:
q.attr.name = token.lexema
match("TKN_ID")
# Caso especial de que sea ++ o -- Haremos lo sig: --> id := id + 1
if (token.tipo == "TKN_PPLUS") | (token.tipo == "TKN_LLESS"):
lex = token.lexema[0] # + o -
if lex == "+":
tipo = "TKN_ADD"
else:
tipo = "TKN_MINUS"
# Creamos tokens Artificiales y añadimos a tokens[]
tokenA = tokens[contador - 2] # id
tokenB = Token(token.linea, token.columna, tipo, lex) # - o +
tokenC = Token(token.linea, token.columna, "TKN_NUM", "1") # 1
# Establecemos nodo de asignación :=
token = Token(token.linea, token.columna, "TKN_ASSIGN", ":=")
tokens[contador - 1] = token # Actualizamos array, cambiando el PPLUS por ":="
t = newStmtNode(StmtKind.AssignK)
match("TKN_ASSIGN")
if t is not None:
t.attr.name = token
# Añado a tokens[]:
tokens.insert(contador - 1, tokenA)
tokens.insert(contador, tokenB)
tokens.insert(contador + 1, tokenC)
token = tokens[contador - 1]
# contador -= 1
if t is not None:
t.branch[0] = q
t.branch[1] = expresion(synchset + ["TKN_SEMICOLON", "TKN_RPAREN"])
# Si no, es una asignación
else:
if token.tipo == "TKN_ASSIGN":
t = newStmtNode(StmtKind.AssignK)
else:
tAux = token
token = Token(token.linea, token.columna, "TKN_ASSIGN", ":=")
t = newStmtNode(StmtKind.AssignK)
token = tAux
match("TKN_ASSIGN")
# t = newStmtNode(StmtKind.AssignK)
if t is not None:
t.attr.name = token
# match("TKN_ASSIGN")
if t is not None:
t.branch[0] = q
t.branch[1] = expresion(synchset + ["TKN_SEMICOLON", "TKN_RPAREN"])
match("TKN_SEMICOLON")
# checkinput(synchset, firstset)
return t
def cin_stmt(synchset):
pass
global token
firstset = ["TKN_CIN"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = newStmtNode(StmtKind.CinK)
match("TKN_CIN")
if t is not None:
t.attr.name = token.lexema
t.branch[0] = newExpNode(ExpKind.IdK)
match("TKN_ID")
match("TKN_SEMICOLON")
# checkinput(synchset, firstset)
return t
def cout_stmt(synchset):
pass
global token
firstset = ["TKN_COUT"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = newStmtNode(StmtKind.CoutK)
match("TKN_COUT")
if t is not None:
t.branch[0] = expresion(["TKN_SEMICOLON", "TKN_RPAREN"])
match("TKN_SEMICOLON")
# checkinput(synchset, firstset)
return t
def isLogic():
pass
global token
if (token.tipo == "TKN_LESS") | (token.tipo == "TKN_ELESS"):
return True
elif (token.tipo == "TKN_EQUAL") | (token.tipo == "TKN_NEQUAL"):
return True
elif (token.tipo == "TKN_MORE") | (token.tipo == "TKN_EMORE"):
return True
else:
return False
def expresion(synchset):
pass
global token
t = TreeNode()
firstset = ["TKN_LPAREN", "TKN_ID", "TKN_NUM"]
synchset += []
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = simple_exp(synchset)
if isLogic():
p = newExpNode(ExpKind.OpK)
if p is not None:
p.branch[0] = t
p.attr.op = token.tipo
t = p
match(token.tipo)
if t is not None:
t.branch[1] = simple_exp(synchset)
checkinput(synchset, firstset)
return t
def simple_exp(synchset):
pass
global token
t = TreeNode()
firstset = ["TKN_LPAREN", "TKN_NUM", "TKN_ID"]
synchset += ["TKN_LESS", "TKN_ELESS", "TKN_MORE", "TKN_EMORE", "TKN_EQUAL", "TKN_NEQUAL"]
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = term(synchset)
while (token.tipo == "TKN_ADD") | (token.tipo == "TKN_MINUS"):
p = newExpNode(ExpKind.OpK)
if p is not None:
p.branch[0] = t
p.attr.op = token.tipo
t = p
match(token.tipo)
# En caso de que haya dos operadores seguidos:
while (token.tipo == "TKN_ADD") | (token.tipo == "TKN_MINUS"):
print("Syntax error, multiple operator detected at column " + token.columna + " at line " +
token.linea)
output.write("Syntax error, multiple operator detected at column " + token.columna +
" at line " + token.linea + "\n")
token = getToken()
t.branch[1] = term(synchset)
checkinput(synchset, firstset)
return t
def term(synchset):
pass
global token
t = TreeNode()
firstset = ["TKN_LPAREN", "TKN_NUM", "TKN_ID"]
synchset += ["TKN_ADD", "TKN_MINUS"]
checkinput(firstset, synchset)
if not token.tipo in synchset:
t = factor(synchset)
while (token.tipo == "TKN_MULTI") | (token.tipo == "TKN_DIV"):
p = newExpNode(ExpKind.OpK)
if p is not None:
p.branch[0] = t
p.attr.op = token.tipo
t = p
match(token.tipo)
while (token.tipo == "TKN_MULTI") | (token.tipo == "TKN_DIV"):
print("Syntax error, multiple operator detected at column " + token.columna + " at line " +
token.linea)
output.write("Syntax error, multiple operator detected at column " + token.columna +
" at line " + token.linea + "\n")
token = getToken()
p.branch[1] = factor(synchset)
checkinput(synchset, firstset)
return t
def factor(synchset):
pass
global token
t = TreeNode()
firstset = ["TKN_LPAREN", "TKN_NUM", "TKN_ID"]
synchset += ["TKN_MULTI", "TKN_DIV"]
if not token.tipo in synchset:
if token.tipo == "TKN_NUM":
t = newExpNode(ExpKind.ConstK)
if t is None:
try:
valor = float(token.lexema)
t.attr.val = valor
except:
print("No fue posible convertir el lexema a float")
match("TKN_NUM")
elif token.tipo == "TKN_ID":
t = newExpNode(ExpKind.IdK)
if t is None:
t.attr.name = token.lexema
match("TKN_ID")
elif token.tipo == "TKN_LPAREN":
match("TKN_LPAREN")
t = expresion(["TKN_SEMICOLON", "TKN_RPAREN"])
match("TKN_RPAREN")
# checkinput(synchset, firstset)
return t
def parse():
global token
t = TreeNode()
token = getToken()
t = main()
return t
def main1():
pass
t = parse()
printTree(t)
return t
def printTree(root):
global output
# serializo el objeto root y lo guardo en el archivo 'tree.bin'
with open('tree.bin', 'wb') as f:
pickle.dump(root, f)
i = 0
try:
print(root.token.lexema)
output.write(root.token.lexema + "\n")
while root.branch[i] is not None:
printBranch(root.branch[i], " ")
i += 1
except:
pass
def printBranch(root, tabulacion):
global output
print(tabulacion, root.token.lexema)
output.write(tabulacion + root.token.lexema + "\n")
i = 0
try:
while root.branch[i] is not None:
printBranch(root.branch[i], tabulacion + " ")
i += 1
except:
pass
i = 0
try:
while root.sibling[i] is not None:
printBranch(root.sibling[i], tabulacion)
i += 1
except:
pass
def printSibling(root, tabulacion):
print(tabulacion, root.token.lexema)
i = 0
try:
while root.branch[i] is not None:
printBranch(root.branch[i], tabulacion + " ")
i += 1
except:
pass
# Quitamos errores que se repitan de una misma linea
def cleanErrorFile():
errores = []
noErrores = []
# Separamos errores del árbol
try:
output = open("Tree.txt", "r")
for line in output:
if "Syntax error" in line:
errores.append(line[:-1])
else:
noErrores.append(line[:-1])
output.close()
except:
print("Problema en txt - cleanErrorFile()")
pass
# Quitamos errores duplicados
errores2 = []
try:
atLine = "asdasdasxx"
for error in errores:
if not atLine in error[-7:]:
errores2.append(error)
atLine = error[-7:]
if "EOF" in error:
errores2.append(error)
except:
print("Problema en txt - cleanErrorFile()")
pass
# Juntamos los errores con el árbol
try:
output = open("Tree.txt", "w+")
for error in errores2:
output.write(error + "\n")
for valido in noErrores:
output.write(valido + "\n")
output.close()
except:
print("Problema al escribir txt - cleanErrorFile()")
# Iniciamos programa:
def init_sintactic():
global output
try:
output = open("Tree.txt", "w+")
tree = main1()
output.close()
cleanErrorFile()
return tree
except Exception as e:
print("Error en el main: ", e)
pass
# Si se llama unicamente el archivo "Sintactico.py":
# Cuando se llama desde el Análisis gramátical se va directamente a init_sintactic.
if __name__ == '__main__':
init_sintactic()
# NOTA: para que muestre el árbol en el IDE habrá que descomentar las lineas referentes al -print- dentro de
# printTree(), printSibling y printBranch
# -------------------------- PRIMEROS --------------------------
# primero(programa) { main } |
# primero(lista-declaración) { int, real, boolean } |
# primero(declaración) { int, real, boolean } |
# primero(tipo) { int, real, boolean } |
# primero(lista-variables) { identificador } |
# primero(lista-sentencia) { if, while, repeat, cin, cout, {, identificador }
# primero(sentencia) { if, while, repeat, cin, cout, {, identificador }
# primero(sent-if) { if } |
# primero(sent-while) { while } |
# primero(sent-repeat) { repeat } |
# primero(sent-cin) { cin } |
# primero(sent-cout) { cout } |
# primero(bloque) { { } |
# primero(asignación) { identificador } |
# primero(expresión) { (, numero, identificador } |
# primero(relación) { <=, <, >, >=, ==, != } |
# primero(exp) { (, numero, identificador } |
# primero(opsuma) { +, - } |
# primero(termino) { (, numero, identificador } |
# primero(opmult) { *, / } |
# primero(factor) { (, numero, identificador } |
# ---------------------------------------------------------------
# -------------------------- SIGUIENTES ----------------------------
# siguiente(programa) { } |
# siguiente(lista-declaración) { if, while, repeat, cin, cout, {, identificador }
# siguiente(declaración) { ; } |
# siguiente(tipo) { identificador } |
# siguiente(lista-variables) { ; } |
# siguiente(lista-sentencia) { } } |
# siguiente(sentencia) { } } |
# siguiente(sent-if) { } } |
# siguiente(sent-while) { } } |
# siguiente(sent-repeat) { } } |
# siguiente(sent-cin) { } } |
# siguiente(sent-cout) { } } |
# siguiente(bloque) { until, else, } } |
# siguiente(asignación) { } } |
# siguiente(expresión) { ;, ) } |
# siguiente(relación) { (, numero, identificador } |
# siguiente(exp) { <=, <, >, >=, ==, !=, ;, ) } |
# siguiente(opsuma) { (, numero, identificador } |
# siguiente(termino) { +, -, <=, <, >, >=, ==, !=, ;, ) } |
# siguiente(opmult) { (, numero, identificador } |
# siguiente(factor) { *, /, +, -, <=, <, >, >=, ==, !=, ;, ) } |
# -------------------------------------------------------------------