diff --git a/MEPA b/MEPA index f4b8de02ec1cce17e257c7e756b758d8b5171a3c..9acacb38d3a1c3fcc3b3304ce9a103300994dbbc 100644 --- a/MEPA +++ b/MEPA @@ -5,13 +5,15 @@ R01: ENPR 1 AMEM 1 DSVS R02 R02: NADA - CRVL 1,-4 + CRVI 1,-5 ARMZ 1,0 + CRCT 1 + ARMI 1,-5 DMEM 1 R00: NADA CRCT 8 ARMZ 0,0 - CRVL 0,0 + CREN 0,0 CRCT 2 CHPR R01,0 DMEM 0 diff --git a/compilador.output b/compilador.output index ba68368d2356f1a6c323a13e92ec00d655addd6c..59f20c0024161eb8c73745b7c006403dbca36fff 100644 --- a/compilador.output +++ b/compilador.output @@ -119,56 +119,61 @@ Grammar 60 lista_parametros: ABRE_PARENTESES lista_parametros_parenteses FECHA_PARENTESES 61 | /* empty */ - 62 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples - 63 | expressao_simples + 62 @16: /* empty */ - 64 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES + 63 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA @16 expressao_simples - 65 lista_leituras: lista_leituras VIRGULA simb_leitura - 66 | simb_leitura + 64 @17: /* empty */ - 67 simb_leitura: IDENT + 65 lista_parametros_parenteses: @17 expressao_simples - 68 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES + 66 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES - 69 lista_escritas: lista_escritas VIRGULA expressao_simples - 70 | expressao_simples + 67 lista_leituras: lista_leituras VIRGULA simb_leitura + 68 | simb_leitura - 71 expressao: expressao IGUAL expressao_simples - 72 | expressao DIFERENTE expressao_simples - 73 | expressao MENOR expressao_simples - 74 | expressao MENOR_IGUAL expressao_simples - 75 | expressao MAIOR expressao_simples - 76 | expressao MAIOR_IGUAL expressao_simples - 77 | expressao_simples + 69 simb_leitura: IDENT - 78 expressao_simples: expressao_simples MAIS termo - 79 | expressao_simples MENOS termo - 80 | termo + 70 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES - 81 termo: termo ASTERISCO fator - 82 | termo DIV fator - 83 | fator + 71 lista_escritas: lista_escritas VIRGULA expressao_simples + 72 | expressao_simples - 84 fator: IDENT - 85 | NUMERO + 73 expressao: expressao IGUAL expressao_simples + 74 | expressao DIFERENTE expressao_simples + 75 | expressao MENOR expressao_simples + 76 | expressao MENOR_IGUAL expressao_simples + 77 | expressao MAIOR expressao_simples + 78 | expressao MAIOR_IGUAL expressao_simples + 79 | expressao_simples - 86 numero: NUMERO + 80 expressao_simples: expressao_simples MAIS termo + 81 | expressao_simples MENOS termo + 82 | termo - 87 @16: /* empty */ + 83 termo: termo ASTERISCO fator + 84 | termo DIV fator + 85 | fator - 88 @17: /* empty */ + 86 fator: IDENT + 87 | NUMERO - 89 comando_repetitivo: @16 WHILE expressao DO @17 comando_sem_rotulo + 88 numero: NUMERO - 90 comando_condicional: if_then cond_else + 89 @18: /* empty */ - 91 cond_else: ELSE comando_sem_rotulo - 92 | /* empty */ + 90 @19: /* empty */ - 93 @18: /* empty */ + 91 comando_repetitivo: @18 WHILE expressao DO @19 comando_sem_rotulo - 94 if_then: IF expressao @18 THEN comando_sem_rotulo + 92 comando_condicional: if_then cond_else + + 93 cond_else: ELSE comando_sem_rotulo + 94 | /* empty */ + + 95 @20: /* empty */ + + 96 if_then: IF expressao @20 THEN comando_sem_rotulo Terminals, with rules where they appear @@ -176,16 +181,16 @@ Terminals, with rules where they appear $end (0) 0 error (256) PROGRAM (258) 2 -ABRE_PARENTESES (259) 2 29 60 64 68 -FECHA_PARENTESES (260) 2 29 60 64 68 -VIRGULA (261) 6 18 20 37 62 65 69 +ABRE_PARENTESES (259) 2 29 60 66 70 +FECHA_PARENTESES (260) 2 29 60 66 70 +VIRGULA (261) 6 18 20 37 63 67 71 PONTO_E_VIRGULA (262) 2 16 26 32 41 42 DOIS_PONTOS (263) 16 34 36 44 PONTO (264) 2 T_BEGIN (265) 40 T_END (266) 40 VAR (267) 10 34 -IDENT (268) 2 17 18 19 20 21 26 39 53 67 84 +IDENT (268) 2 17 18 19 20 21 26 39 53 69 86 ATRIBUICAO (269) 57 LABEL (270) 6 TYPE (271) @@ -193,27 +198,27 @@ ARRAY (272) PROCEDURE (273) 26 FUNCTION (274) GOTO (275) -IF (276) 94 -THEN (277) 94 -ELSE (278) 91 -WHILE (279) 89 -DO (280) 89 +IF (276) 96 +THEN (277) 96 +ELSE (278) 93 +WHILE (279) 91 +DO (280) 91 OR (281) -DIV (282) 82 +DIV (282) 84 AND (283) NOT (284) -IGUAL (285) 71 -DIFERENTE (286) 72 -MENOR_IGUAL (287) 74 -MAIOR_IGUAL (288) 76 -MENOR (289) 73 -MAIOR (290) 75 -MAIS (291) 78 -MENOS (292) 79 -ASTERISCO (293) 81 -NUMERO (294) 85 86 -READ (295) 64 -WRITE (296) 68 +IGUAL (285) 73 +DIFERENTE (286) 74 +MENOR_IGUAL (287) 76 +MAIOR_IGUAL (288) 78 +MENOR (289) 75 +MAIOR (290) 77 +MAIS (291) 80 +MENOS (292) 81 +ASTERISCO (293) 83 +NUMERO (294) 87 88 +READ (295) 66 +WRITE (296) 70 LOWER_THAN_ELSE (297) @@ -286,7 +291,7 @@ comandos (74) comando (75) on left: 44 45, on right: 41 42 comando_sem_rotulo (76) - on left: 46 47 48 49 50 51, on right: 44 45 89 91 94 + on left: 46 47 48 49 50 51, on right: 44 45 91 93 96 atribuicao_ou_procedimento (77) on left: 53, on right: 46 @13 (78) @@ -304,42 +309,46 @@ chamada_procedimento (82) lista_parametros (84) on left: 60 61, on right: 59 lista_parametros_parenteses (85) - on left: 62 63, on right: 60 62 -leitura (86) - on left: 64, on right: 50 -lista_leituras (87) - on left: 65 66, on right: 64 65 -simb_leitura (88) - on left: 67, on right: 65 66 -escrita (89) - on left: 68, on right: 51 -lista_escritas (90) - on left: 69 70, on right: 68 69 -expressao (91) - on left: 71 72 73 74 75 76 77, on right: 71 72 73 74 75 76 89 94 -expressao_simples (92) - on left: 78 79 80, on right: 57 62 63 69 70 71 72 73 74 75 76 77 - 78 79 -termo (93) - on left: 81 82 83, on right: 78 79 80 81 82 -fator (94) - on left: 84 85, on right: 81 82 83 -numero (95) - on left: 86, on right: 44 -comando_repetitivo (96) - on left: 89, on right: 49 -@16 (97) - on left: 87, on right: 89 -@17 (98) - on left: 88, on right: 89 -comando_condicional (99) - on left: 90, on right: 48 -cond_else (100) - on left: 91 92, on right: 90 -if_then (101) - on left: 94, on right: 90 -@18 (102) - on left: 93, on right: 94 + on left: 63 65, on right: 60 63 +@16 (86) + on left: 62, on right: 63 +@17 (87) + on left: 64, on right: 65 +leitura (88) + on left: 66, on right: 50 +lista_leituras (89) + on left: 67 68, on right: 66 67 +simb_leitura (90) + on left: 69, on right: 67 68 +escrita (91) + on left: 70, on right: 51 +lista_escritas (92) + on left: 71 72, on right: 70 71 +expressao (93) + on left: 73 74 75 76 77 78 79, on right: 73 74 75 76 77 78 91 96 +expressao_simples (94) + on left: 80 81 82, on right: 57 63 65 71 72 73 74 75 76 77 78 79 + 80 81 +termo (95) + on left: 83 84 85, on right: 80 81 82 83 84 +fator (96) + on left: 86 87, on right: 83 84 85 +numero (97) + on left: 88, on right: 44 +comando_repetitivo (98) + on left: 91, on right: 49 +@18 (99) + on left: 89, on right: 91 +@19 (100) + on left: 90, on right: 91 +comando_condicional (101) + on left: 92, on right: 48 +cond_else (102) + on left: 93 94, on right: 92 +if_then (103) + on left: 96, on right: 92 +@20 (104) + on left: 95, on right: 96 state 0 @@ -635,7 +644,7 @@ state 34 READ shift, and go to state 42 WRITE shift, and go to state 43 - WHILE reduce using rule 87 (@16) + WHILE reduce using rule 89 (@18) $default reduce using rule 43 (comandos) comando_composto go to state 44 @@ -647,7 +656,7 @@ state 34 escrita go to state 50 numero go to state 51 comando_repetitivo go to state 52 - @16 go to state 53 + @18 go to state 53 comando_condicional go to state 54 if_then go to state 55 @@ -697,7 +706,7 @@ state 39 state 40 - 94 if_then: IF . expressao @18 THEN comando_sem_rotulo + 96 if_then: IF . expressao @20 THEN comando_sem_rotulo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -710,21 +719,21 @@ state 40 state 41 - 86 numero: NUMERO . + 88 numero: NUMERO . - $default reduce using rule 86 (numero) + $default reduce using rule 88 (numero) state 42 - 64 leitura: READ . ABRE_PARENTESES lista_leituras FECHA_PARENTESES + 66 leitura: READ . ABRE_PARENTESES lista_leituras FECHA_PARENTESES ABRE_PARENTESES shift, and go to state 68 state 43 - 68 escrita: WRITE . ABRE_PARENTESES lista_escritas FECHA_PARENTESES + 70 escrita: WRITE . ABRE_PARENTESES lista_escritas FECHA_PARENTESES ABRE_PARENTESES shift, and go to state 69 @@ -795,7 +804,7 @@ state 52 state 53 - 89 comando_repetitivo: @16 . WHILE expressao DO @17 comando_sem_rotulo + 91 comando_repetitivo: @18 . WHILE expressao DO @19 comando_sem_rotulo WHILE shift, and go to state 73 @@ -809,11 +818,11 @@ state 54 state 55 - 90 comando_condicional: if_then . cond_else + 92 comando_condicional: if_then . cond_else ELSE shift, and go to state 74 - $default reduce using rule 92 (cond_else) + $default reduce using rule 94 (cond_else) cond_else go to state 75 @@ -873,27 +882,27 @@ state 61 state 62 - 84 fator: IDENT . + 86 fator: IDENT . - $default reduce using rule 84 (fator) + $default reduce using rule 86 (fator) state 63 - 85 fator: NUMERO . + 87 fator: NUMERO . - $default reduce using rule 85 (fator) + $default reduce using rule 87 (fator) state 64 - 71 expressao: expressao . IGUAL expressao_simples - 72 | expressao . DIFERENTE expressao_simples - 73 | expressao . MENOR expressao_simples - 74 | expressao . MENOR_IGUAL expressao_simples - 75 | expressao . MAIOR expressao_simples - 76 | expressao . MAIOR_IGUAL expressao_simples - 94 if_then: IF expressao . @18 THEN comando_sem_rotulo + 73 expressao: expressao . IGUAL expressao_simples + 74 | expressao . DIFERENTE expressao_simples + 75 | expressao . MENOR expressao_simples + 76 | expressao . MENOR_IGUAL expressao_simples + 77 | expressao . MAIOR expressao_simples + 78 | expressao . MAIOR_IGUAL expressao_simples + 96 if_then: IF expressao . @20 THEN comando_sem_rotulo IGUAL shift, and go to state 84 DIFERENTE shift, and go to state 85 @@ -902,45 +911,45 @@ state 64 MENOR shift, and go to state 88 MAIOR shift, and go to state 89 - $default reduce using rule 93 (@18) + $default reduce using rule 95 (@20) - @18 go to state 90 + @20 go to state 90 state 65 - 77 expressao: expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 79 expressao: expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 77 (expressao) + $default reduce using rule 79 (expressao) state 66 - 80 expressao_simples: termo . - 81 termo: termo . ASTERISCO fator - 82 | termo . DIV fator + 82 expressao_simples: termo . + 83 termo: termo . ASTERISCO fator + 84 | termo . DIV fator DIV shift, and go to state 93 ASTERISCO shift, and go to state 94 - $default reduce using rule 80 (expressao_simples) + $default reduce using rule 82 (expressao_simples) state 67 - 83 termo: fator . + 85 termo: fator . - $default reduce using rule 83 (termo) + $default reduce using rule 85 (termo) state 68 - 64 leitura: READ ABRE_PARENTESES . lista_leituras FECHA_PARENTESES + 66 leitura: READ ABRE_PARENTESES . lista_leituras FECHA_PARENTESES IDENT shift, and go to state 95 @@ -950,7 +959,7 @@ state 68 state 69 - 68 escrita: WRITE ABRE_PARENTESES . lista_escritas FECHA_PARENTESES + 70 escrita: WRITE ABRE_PARENTESES . lista_escritas FECHA_PARENTESES IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -982,7 +991,7 @@ state 71 T_END reduce using rule 42 (comandos) T_END [reduce using rule 43 (comandos)] - WHILE reduce using rule 87 (@16) + WHILE reduce using rule 89 (@18) $default reduce using rule 42 (comandos) comando_composto go to state 44 @@ -994,7 +1003,7 @@ state 71 escrita go to state 50 numero go to state 51 comando_repetitivo go to state 52 - @16 go to state 53 + @18 go to state 53 comando_condicional go to state 54 if_then go to state 55 @@ -1009,7 +1018,7 @@ state 72 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 87 (@16) + $default reduce using rule 89 (@18) comando_composto go to state 44 comando_sem_rotulo go to state 101 @@ -1017,14 +1026,14 @@ state 72 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @16 go to state 53 + @18 go to state 53 comando_condicional go to state 54 if_then go to state 55 state 73 - 89 comando_repetitivo: @16 WHILE . expressao DO @17 comando_sem_rotulo + 91 comando_repetitivo: @18 WHILE . expressao DO @19 comando_sem_rotulo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1037,7 +1046,7 @@ state 73 state 74 - 91 cond_else: ELSE . comando_sem_rotulo + 93 cond_else: ELSE . comando_sem_rotulo T_BEGIN shift, and go to state 34 IDENT shift, and go to state 39 @@ -1045,7 +1054,7 @@ state 74 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 87 (@16) + $default reduce using rule 89 (@18) comando_composto go to state 44 comando_sem_rotulo go to state 103 @@ -1053,16 +1062,16 @@ state 74 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @16 go to state 53 + @18 go to state 53 comando_condicional go to state 54 if_then go to state 55 state 75 - 90 comando_condicional: if_then cond_else . + 92 comando_condicional: if_then cond_else . - $default reduce using rule 90 (comando_condicional) + $default reduce using rule 92 (comando_condicional) state 76 @@ -1138,7 +1147,7 @@ state 83 state 84 - 71 expressao: expressao IGUAL . expressao_simples + 73 expressao: expressao IGUAL . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1150,7 +1159,7 @@ state 84 state 85 - 72 expressao: expressao DIFERENTE . expressao_simples + 74 expressao: expressao DIFERENTE . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1162,7 +1171,7 @@ state 85 state 86 - 74 expressao: expressao MENOR_IGUAL . expressao_simples + 76 expressao: expressao MENOR_IGUAL . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1174,7 +1183,7 @@ state 86 state 87 - 76 expressao: expressao MAIOR_IGUAL . expressao_simples + 78 expressao: expressao MAIOR_IGUAL . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1186,7 +1195,7 @@ state 87 state 88 - 73 expressao: expressao MENOR . expressao_simples + 75 expressao: expressao MENOR . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1198,7 +1207,7 @@ state 88 state 89 - 75 expressao: expressao MAIOR . expressao_simples + 77 expressao: expressao MAIOR . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1210,14 +1219,14 @@ state 89 state 90 - 94 if_then: IF expressao @18 . THEN comando_sem_rotulo + 96 if_then: IF expressao @20 . THEN comando_sem_rotulo THEN shift, and go to state 119 state 91 - 78 expressao_simples: expressao_simples MAIS . termo + 80 expressao_simples: expressao_simples MAIS . termo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1228,7 +1237,7 @@ state 91 state 92 - 79 expressao_simples: expressao_simples MENOS . termo + 81 expressao_simples: expressao_simples MENOS . termo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1239,7 +1248,7 @@ state 92 state 93 - 82 termo: termo DIV . fator + 84 termo: termo DIV . fator IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1249,7 +1258,7 @@ state 93 state 94 - 81 termo: termo ASTERISCO . fator + 83 termo: termo ASTERISCO . fator IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1259,15 +1268,15 @@ state 94 state 95 - 67 simb_leitura: IDENT . + 69 simb_leitura: IDENT . - $default reduce using rule 67 (simb_leitura) + $default reduce using rule 69 (simb_leitura) state 96 - 64 leitura: READ ABRE_PARENTESES lista_leituras . FECHA_PARENTESES - 65 lista_leituras: lista_leituras . VIRGULA simb_leitura + 66 leitura: READ ABRE_PARENTESES lista_leituras . FECHA_PARENTESES + 67 lista_leituras: lista_leituras . VIRGULA simb_leitura FECHA_PARENTESES shift, and go to state 124 VIRGULA shift, and go to state 125 @@ -1275,15 +1284,15 @@ state 96 state 97 - 66 lista_leituras: simb_leitura . + 68 lista_leituras: simb_leitura . - $default reduce using rule 66 (lista_leituras) + $default reduce using rule 68 (lista_leituras) state 98 - 68 escrita: WRITE ABRE_PARENTESES lista_escritas . FECHA_PARENTESES - 69 lista_escritas: lista_escritas . VIRGULA expressao_simples + 70 escrita: WRITE ABRE_PARENTESES lista_escritas . FECHA_PARENTESES + 71 lista_escritas: lista_escritas . VIRGULA expressao_simples FECHA_PARENTESES shift, and go to state 126 VIRGULA shift, and go to state 127 @@ -1291,14 +1300,14 @@ state 98 state 99 - 70 lista_escritas: expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 72 lista_escritas: expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 70 (lista_escritas) + $default reduce using rule 72 (lista_escritas) state 100 @@ -1317,13 +1326,13 @@ state 101 state 102 - 71 expressao: expressao . IGUAL expressao_simples - 72 | expressao . DIFERENTE expressao_simples - 73 | expressao . MENOR expressao_simples - 74 | expressao . MENOR_IGUAL expressao_simples - 75 | expressao . MAIOR expressao_simples - 76 | expressao . MAIOR_IGUAL expressao_simples - 89 comando_repetitivo: @16 WHILE expressao . DO @17 comando_sem_rotulo + 73 expressao: expressao . IGUAL expressao_simples + 74 | expressao . DIFERENTE expressao_simples + 75 | expressao . MENOR expressao_simples + 76 | expressao . MENOR_IGUAL expressao_simples + 77 | expressao . MAIOR expressao_simples + 78 | expressao . MAIOR_IGUAL expressao_simples + 91 comando_repetitivo: @18 WHILE expressao . DO @19 comando_sem_rotulo DO shift, and go to state 128 IGUAL shift, and go to state 84 @@ -1336,9 +1345,9 @@ state 102 state 103 - 91 cond_else: ELSE comando_sem_rotulo . + 93 cond_else: ELSE comando_sem_rotulo . - $default reduce using rule 91 (cond_else) + $default reduce using rule 93 (cond_else) state 104 @@ -1411,13 +1420,10 @@ state 111 60 lista_parametros: ABRE_PARENTESES . lista_parametros_parenteses FECHA_PARENTESES - IDENT shift, and go to state 62 - NUMERO shift, and go to state 63 + $default reduce using rule 64 (@17) lista_parametros_parenteses go to state 137 - expressao_simples go to state 138 - termo go to state 66 - fator go to state 67 + @17 go to state 138 state 112 @@ -1429,79 +1435,79 @@ state 112 state 113 - 71 expressao: expressao IGUAL expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 73 expressao: expressao IGUAL expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 71 (expressao) + $default reduce using rule 73 (expressao) state 114 - 72 expressao: expressao DIFERENTE expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 74 expressao: expressao DIFERENTE expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 72 (expressao) + $default reduce using rule 74 (expressao) state 115 - 74 expressao: expressao MENOR_IGUAL expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 76 expressao: expressao MENOR_IGUAL expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 74 (expressao) + $default reduce using rule 76 (expressao) state 116 - 76 expressao: expressao MAIOR_IGUAL expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 78 expressao: expressao MAIOR_IGUAL expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 76 (expressao) + $default reduce using rule 78 (expressao) state 117 - 73 expressao: expressao MENOR expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 75 expressao: expressao MENOR expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 73 (expressao) + $default reduce using rule 75 (expressao) state 118 - 75 expressao: expressao MAIOR expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 77 expressao: expressao MAIOR expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 75 (expressao) + $default reduce using rule 77 (expressao) state 119 - 94 if_then: IF expressao @18 THEN . comando_sem_rotulo + 96 if_then: IF expressao @20 THEN . comando_sem_rotulo T_BEGIN shift, and go to state 34 IDENT shift, and go to state 39 @@ -1509,7 +1515,7 @@ state 119 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 87 (@16) + $default reduce using rule 89 (@18) comando_composto go to state 44 comando_sem_rotulo go to state 139 @@ -1517,59 +1523,59 @@ state 119 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @16 go to state 53 + @18 go to state 53 comando_condicional go to state 54 if_then go to state 55 state 120 - 78 expressao_simples: expressao_simples MAIS termo . - 81 termo: termo . ASTERISCO fator - 82 | termo . DIV fator + 80 expressao_simples: expressao_simples MAIS termo . + 83 termo: termo . ASTERISCO fator + 84 | termo . DIV fator DIV shift, and go to state 93 ASTERISCO shift, and go to state 94 - $default reduce using rule 78 (expressao_simples) + $default reduce using rule 80 (expressao_simples) state 121 - 79 expressao_simples: expressao_simples MENOS termo . - 81 termo: termo . ASTERISCO fator - 82 | termo . DIV fator + 81 expressao_simples: expressao_simples MENOS termo . + 83 termo: termo . ASTERISCO fator + 84 | termo . DIV fator DIV shift, and go to state 93 ASTERISCO shift, and go to state 94 - $default reduce using rule 79 (expressao_simples) + $default reduce using rule 81 (expressao_simples) state 122 - 82 termo: termo DIV fator . + 84 termo: termo DIV fator . - $default reduce using rule 82 (termo) + $default reduce using rule 84 (termo) state 123 - 81 termo: termo ASTERISCO fator . + 83 termo: termo ASTERISCO fator . - $default reduce using rule 81 (termo) + $default reduce using rule 83 (termo) state 124 - 64 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES . + 66 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES . - $default reduce using rule 64 (leitura) + $default reduce using rule 66 (leitura) state 125 - 65 lista_leituras: lista_leituras VIRGULA . simb_leitura + 67 lista_leituras: lista_leituras VIRGULA . simb_leitura IDENT shift, and go to state 95 @@ -1578,14 +1584,14 @@ state 125 state 126 - 68 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES . + 70 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES . - $default reduce using rule 68 (escrita) + $default reduce using rule 70 (escrita) state 127 - 69 lista_escritas: lista_escritas VIRGULA . expressao_simples + 71 lista_escritas: lista_escritas VIRGULA . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -1597,11 +1603,11 @@ state 127 state 128 - 89 comando_repetitivo: @16 WHILE expressao DO . @17 comando_sem_rotulo + 91 comando_repetitivo: @18 WHILE expressao DO . @19 comando_sem_rotulo - $default reduce using rule 88 (@17) + $default reduce using rule 90 (@19) - @17 go to state 142 + @19 go to state 142 state 129 @@ -1667,8 +1673,8 @@ state 135 state 136 57 atribuicao: @14 ATRIBUICAO expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 @@ -1679,7 +1685,7 @@ state 136 state 137 60 lista_parametros: ABRE_PARENTESES lista_parametros_parenteses . FECHA_PARENTESES - 62 lista_parametros_parenteses: lista_parametros_parenteses . VIRGULA expressao_simples + 63 lista_parametros_parenteses: lista_parametros_parenteses . VIRGULA @16 expressao_simples FECHA_PARENTESES shift, and go to state 149 VIRGULA shift, and go to state 150 @@ -1687,45 +1693,45 @@ state 137 state 138 - 63 lista_parametros_parenteses: expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 65 lista_parametros_parenteses: @17 . expressao_simples - MAIS shift, and go to state 91 - MENOS shift, and go to state 92 + IDENT shift, and go to state 62 + NUMERO shift, and go to state 63 - $default reduce using rule 63 (lista_parametros_parenteses) + expressao_simples go to state 151 + termo go to state 66 + fator go to state 67 state 139 - 94 if_then: IF expressao @18 THEN comando_sem_rotulo . + 96 if_then: IF expressao @20 THEN comando_sem_rotulo . - $default reduce using rule 94 (if_then) + $default reduce using rule 96 (if_then) state 140 - 65 lista_leituras: lista_leituras VIRGULA simb_leitura . + 67 lista_leituras: lista_leituras VIRGULA simb_leitura . - $default reduce using rule 65 (lista_leituras) + $default reduce using rule 67 (lista_leituras) state 141 - 69 lista_escritas: lista_escritas VIRGULA expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 71 lista_escritas: lista_escritas VIRGULA expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo MAIS shift, and go to state 91 MENOS shift, and go to state 92 - $default reduce using rule 69 (lista_escritas) + $default reduce using rule 71 (lista_escritas) state 142 - 89 comando_repetitivo: @16 WHILE expressao DO @17 . comando_sem_rotulo + 91 comando_repetitivo: @18 WHILE expressao DO @19 . comando_sem_rotulo T_BEGIN shift, and go to state 34 IDENT shift, and go to state 39 @@ -1733,15 +1739,15 @@ state 142 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 87 (@16) + $default reduce using rule 89 (@18) comando_composto go to state 44 - comando_sem_rotulo go to state 151 + comando_sem_rotulo go to state 152 atribuicao_ou_procedimento go to state 48 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @16 go to state 53 + @18 go to state 53 comando_condicional go to state 54 if_then go to state 55 @@ -1750,7 +1756,7 @@ state 143 34 secao_pfs: VAR @11 lista_id_pf . DOIS_PONTOS tipo - DOIS_PONTOS shift, and go to state 152 + DOIS_PONTOS shift, and go to state 153 state 144 @@ -1773,7 +1779,7 @@ state 146 IDENT shift, and go to state 57 - tipo go to state 153 + tipo go to state 154 state 147 @@ -1782,7 +1788,7 @@ state 147 IDENT shift, and go to state 132 - lista_id_pf go to state 154 + lista_id_pf go to state 155 parametro go to state 134 @@ -1802,60 +1808,81 @@ state 149 state 150 - 62 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA . expressao_simples + 63 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA . @16 expressao_simples - IDENT shift, and go to state 62 - NUMERO shift, and go to state 63 + $default reduce using rule 62 (@16) - expressao_simples go to state 155 - termo go to state 66 - fator go to state 67 + @16 go to state 156 state 151 - 89 comando_repetitivo: @16 WHILE expressao DO @17 comando_sem_rotulo . + 65 lista_parametros_parenteses: @17 expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo - $default reduce using rule 89 (comando_repetitivo) + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 65 (lista_parametros_parenteses) state 152 + 91 comando_repetitivo: @18 WHILE expressao DO @19 comando_sem_rotulo . + + $default reduce using rule 91 (comando_repetitivo) + + +state 153 + 34 secao_pfs: VAR @11 lista_id_pf DOIS_PONTOS . tipo IDENT shift, and go to state 57 - tipo go to state 156 + tipo go to state 157 -state 153 +state 154 36 secao_pfs: @12 lista_id_pf DOIS_PONTOS tipo . $default reduce using rule 36 (secao_pfs) -state 154 +state 155 37 lista_id_pf: parametro VIRGULA lista_id_pf . $default reduce using rule 37 (lista_id_pf) -state 155 +state 156 - 62 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples . - 78 expressao_simples: expressao_simples . MAIS termo - 79 | expressao_simples . MENOS termo + 63 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA @16 . expressao_simples - MAIS shift, and go to state 91 - MENOS shift, and go to state 92 + IDENT shift, and go to state 62 + NUMERO shift, and go to state 63 - $default reduce using rule 62 (lista_parametros_parenteses) + expressao_simples go to state 158 + termo go to state 66 + fator go to state 67 -state 156 +state 157 34 secao_pfs: VAR @11 lista_id_pf DOIS_PONTOS tipo . $default reduce using rule 34 (secao_pfs) + + +state 158 + + 63 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA @16 expressao_simples . + 80 expressao_simples: expressao_simples . MAIS termo + 81 | expressao_simples . MENOS termo + + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 63 (lista_parametros_parenteses) diff --git a/compilador.y b/compilador.y index 8c366e669e0b49e6513405c09ebc6650f1d3eca0..c386917c5ad5d7d020916b1428fafc3a1a150a56 100644 --- a/compilador.y +++ b/compilador.y @@ -25,6 +25,7 @@ custom_stack_t *rot; custom_stack_t *proc; int val_ou_ref; +int atr_indireto; %} @@ -211,7 +212,10 @@ secao_pfs: VAR val_ou_ref = REF; } lista_id_pf DOIS_PONTOS tipo - { num_param += num_vars;} + { + num_param += num_vars; + val_ou_ref = VLR; + } | { num_vars = 0; val_ou_ref = VLR; @@ -266,13 +270,20 @@ atribuicao: { if (l_elem == NULL) { yyerror("Variável de destino não declarada"); } else { + if (l_elem->categ == PF && l_elem->info.pf.passagem == REF) + atr_indireto = REF; + else atr_indireto = VLR; destino_nivel = l_elem->nivel; destino_desloc = l_elem->info.vs.desloc; } } ATRIBUICAO expressao_simples { // Gera código ARMZ para armazenar valor char buffer[50]; - sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc); + if (atr_indireto == REF) { + sprintf(buffer, "ARMI %d,%d", destino_nivel, destino_desloc); + } else { + sprintf(buffer, "ARMZ %d,%d", destino_nivel, destino_desloc); + } geraCodigo(NULL, buffer); }; @@ -290,8 +301,7 @@ chamada_procedimento: lista_parametros - { - + { char buffer[50]; mostra_ts(ts); desempilha(buffer, proc); @@ -317,11 +327,26 @@ lista_parametros: ABRE_PARENTESES | ; -lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples +lista_parametros_parenteses: lista_parametros_parenteses VIRGULA + { + char buffer[50]; + desempilha(buffer,proc); + l_elem = busca(buffer,ts); + val_ou_ref = l_elem->info.pr.param[num_param][1]; + empilha(buffer,proc); + } + expressao_simples { num_param++; // Incrementa para cada parâmetro real } - | expressao_simples + | { + char buffer[50]; + desempilha(buffer,proc); + l_elem = busca(buffer,ts); + val_ou_ref = l_elem->info.pr.param[num_param][1]; + empilha(buffer,proc); + } + expressao_simples { num_param++; // Conta o primeiro parâmetro real } @@ -400,8 +425,17 @@ fator: IDENT { yyerror("Variável não declarada"); } else { char buffer[50]; - sprintf(buffer, "CRVL %d,%d", l_elem->nivel, l_elem->info.vs.desloc); + if (val_ou_ref == REF) { + sprintf(buffer, "CREN %d,%d", l_elem->nivel, l_elem->info.vs.desloc); + } + else if (l_elem->categ == PF && l_elem->info.pf.passagem == REF) { + sprintf(buffer, "CRVI %d,%d", l_elem->nivel, l_elem->info.vs.desloc); + } + else { + sprintf(buffer, "CRVL %d,%d", l_elem->nivel, l_elem->info.vs.desloc); + } geraCodigo(NULL, buffer); + val_ou_ref = VLR; } } | NUMERO { diff --git a/teste9.pas b/teste9.pas index 49d026417cd9fdb31760e9c1c0efcd7d61bcef9a..2a56b6947ea6ff612940e56399fc51a9b21e9a0b 100644 --- a/teste9.pas +++ b/teste9.pas @@ -4,6 +4,7 @@ program proc1 (input, output); var z: integer; begin z := a; + a := 1; end; begin x := 8;