diff --git a/MEPA b/MEPA index 1dc6993a142e021179e4267a2f0c184c2f7918e8..0ec3c42a665241694a37dad35ee29c209d9d6278 100644 --- a/MEPA +++ b/MEPA @@ -5,11 +5,14 @@ R01: ENPR 1 AMEM 1 DSVS R02 R02: NADA - CRVL 1,-6 + CRVL 1,-5 ARMZ 1,0 DMEM 1 R00: NADA CRCT 8 ARMZ 0,0 + CRVL 0,0 + CRCT 2 + CHPR R01,0 DMEM 0 PARA diff --git a/compilador.output b/compilador.output index de30752f979b47aae362436be038788b7d4132e4..c8ec77a09587e2aa3058e961cdf1dfc9b4b04eaf 100644 --- a/compilador.output +++ b/compilador.output @@ -108,55 +108,63 @@ Grammar 55 atribuicao: @13 ATRIBUICAO expressao_simples - 56 chamada_procedimento: /* empty */ + 56 @14: /* empty */ - 57 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES + 57 chamada_procedimento: @14 lista_parametros - 58 lista_leituras: lista_leituras VIRGULA simb_leitura - 59 | simb_leitura + 58 lista_parametros: ABRE_PARENTESES lista_parametros_parenteses FECHA_PARENTESES + 59 | /* empty */ - 60 simb_leitura: IDENT + 60 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples + 61 | expressao_simples - 61 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES + 62 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES - 62 lista_escritas: lista_escritas VIRGULA expressao_simples - 63 | expressao_simples + 63 lista_leituras: lista_leituras VIRGULA simb_leitura + 64 | simb_leitura - 64 expressao: expressao IGUAL expressao_simples - 65 | expressao DIFERENTE expressao_simples - 66 | expressao MENOR expressao_simples - 67 | expressao MENOR_IGUAL expressao_simples - 68 | expressao MAIOR expressao_simples - 69 | expressao MAIOR_IGUAL expressao_simples - 70 | expressao_simples + 65 simb_leitura: IDENT - 71 expressao_simples: expressao_simples MAIS termo - 72 | expressao_simples MENOS termo - 73 | termo + 66 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES - 74 termo: termo ASTERISCO fator - 75 | termo DIV fator - 76 | fator + 67 lista_escritas: lista_escritas VIRGULA expressao_simples + 68 | expressao_simples - 77 fator: IDENT - 78 | NUMERO + 69 expressao: expressao IGUAL expressao_simples + 70 | expressao DIFERENTE expressao_simples + 71 | expressao MENOR expressao_simples + 72 | expressao MENOR_IGUAL expressao_simples + 73 | expressao MAIOR expressao_simples + 74 | expressao MAIOR_IGUAL expressao_simples + 75 | expressao_simples - 79 numero: NUMERO + 76 expressao_simples: expressao_simples MAIS termo + 77 | expressao_simples MENOS termo + 78 | termo - 80 @14: /* empty */ + 79 termo: termo ASTERISCO fator + 80 | termo DIV fator + 81 | fator - 81 @15: /* empty */ + 82 fator: IDENT + 83 | NUMERO - 82 comando_repetitivo: @14 WHILE expressao DO @15 comando_sem_rotulo + 84 numero: NUMERO - 83 comando_condicional: if_then cond_else - - 84 cond_else: ELSE comando_sem_rotulo - 85 | /* empty */ + 85 @15: /* empty */ 86 @16: /* empty */ - 87 if_then: IF expressao @16 THEN comando_sem_rotulo + 87 comando_repetitivo: @15 WHILE expressao DO @16 comando_sem_rotulo + + 88 comando_condicional: if_then cond_else + + 89 cond_else: ELSE comando_sem_rotulo + 90 | /* empty */ + + 91 @17: /* empty */ + + 92 if_then: IF expressao @17 THEN comando_sem_rotulo Terminals, with rules where they appear @@ -164,16 +172,16 @@ Terminals, with rules where they appear $end (0) 0 error (256) PROGRAM (258) 2 -ABRE_PARENTESES (259) 2 29 57 61 -FECHA_PARENTESES (260) 2 29 57 61 -VIRGULA (261) 6 18 20 35 58 62 +ABRE_PARENTESES (259) 2 29 58 62 66 +FECHA_PARENTESES (260) 2 29 58 62 66 +VIRGULA (261) 6 18 20 35 60 63 67 PONTO_E_VIRGULA (262) 2 16 26 32 39 40 DOIS_PONTOS (263) 16 34 42 PONTO (264) 2 T_BEGIN (265) 38 T_END (266) 38 VAR (267) 10 -IDENT (268) 2 17 18 19 20 21 26 37 51 60 77 +IDENT (268) 2 17 18 19 20 21 26 37 51 65 82 ATRIBUICAO (269) 55 LABEL (270) 6 TYPE (271) @@ -181,27 +189,27 @@ ARRAY (272) PROCEDURE (273) 26 FUNCTION (274) GOTO (275) -IF (276) 87 -THEN (277) 87 -ELSE (278) 84 -WHILE (279) 82 -DO (280) 82 +IF (276) 92 +THEN (277) 92 +ELSE (278) 89 +WHILE (279) 87 +DO (280) 87 OR (281) -DIV (282) 75 +DIV (282) 80 AND (283) NOT (284) -IGUAL (285) 64 -DIFERENTE (286) 65 -MENOR_IGUAL (287) 67 -MAIOR_IGUAL (288) 69 -MENOR (289) 66 -MAIOR (290) 68 -MAIS (291) 71 -MENOS (292) 72 -ASTERISCO (293) 74 -NUMERO (294) 78 79 -READ (295) 57 -WRITE (296) 61 +IGUAL (285) 69 +DIFERENTE (286) 70 +MENOR_IGUAL (287) 72 +MAIOR_IGUAL (288) 74 +MENOR (289) 71 +MAIOR (290) 73 +MAIS (291) 76 +MENOS (292) 77 +ASTERISCO (293) 79 +NUMERO (294) 83 84 +READ (295) 62 +WRITE (296) 66 LOWER_THAN_ELSE (297) @@ -272,7 +280,7 @@ comandos (73) comando (74) on left: 42 43, on right: 39 40 comando_sem_rotulo (75) - on left: 44 45 46 47 48 49, on right: 42 43 82 84 87 + on left: 44 45 46 47 48 49, on right: 42 43 87 89 92 atribuicao_ou_procedimento (76) on left: 51, on right: 44 @12 (77) @@ -284,41 +292,48 @@ atribuicao (79) @13 (80) on left: 54, on right: 55 chamada_procedimento (81) - on left: 56, on right: 53 -leitura (82) - on left: 57, on right: 48 -lista_leituras (83) - on left: 58 59, on right: 57 58 -simb_leitura (84) - on left: 60, on right: 58 59 -escrita (85) - on left: 61, on right: 49 -lista_escritas (86) - on left: 62 63, on right: 61 62 -expressao (87) - on left: 64 65 66 67 68 69 70, on right: 64 65 66 67 68 69 82 87 -expressao_simples (88) - on left: 71 72 73, on right: 55 62 63 64 65 66 67 68 69 70 71 72 -termo (89) - on left: 74 75 76, on right: 71 72 73 74 75 -fator (90) - on left: 77 78, on right: 74 75 76 -numero (91) - on left: 79, on right: 42 -comando_repetitivo (92) - on left: 82, on right: 47 -@14 (93) - on left: 80, on right: 82 -@15 (94) - on left: 81, on right: 82 -comando_condicional (95) - on left: 83, on right: 46 -cond_else (96) - on left: 84 85, on right: 83 -if_then (97) - on left: 87, on right: 83 -@16 (98) + on left: 57, on right: 53 +@14 (82) + on left: 56, on right: 57 +lista_parametros (83) + on left: 58 59, on right: 57 +lista_parametros_parenteses (84) + on left: 60 61, on right: 58 60 +leitura (85) + on left: 62, on right: 48 +lista_leituras (86) + on left: 63 64, on right: 62 63 +simb_leitura (87) + on left: 65, on right: 63 64 +escrita (88) + on left: 66, on right: 49 +lista_escritas (89) + on left: 67 68, on right: 66 67 +expressao (90) + on left: 69 70 71 72 73 74 75, on right: 69 70 71 72 73 74 87 92 +expressao_simples (91) + on left: 76 77 78, on right: 55 60 61 67 68 69 70 71 72 73 74 75 + 76 77 +termo (92) + on left: 79 80 81, on right: 76 77 78 79 80 +fator (93) + on left: 82 83, on right: 79 80 81 +numero (94) + on left: 84, on right: 42 +comando_repetitivo (95) + on left: 87, on right: 47 +@15 (96) + on left: 85, on right: 87 +@16 (97) on left: 86, on right: 87 +comando_condicional (98) + on left: 88, on right: 46 +cond_else (99) + on left: 89 90, on right: 88 +if_then (100) + on left: 92, on right: 88 +@17 (101) + on left: 91, on right: 92 state 0 @@ -614,7 +629,7 @@ state 34 READ shift, and go to state 42 WRITE shift, and go to state 43 - WHILE reduce using rule 80 (@14) + WHILE reduce using rule 85 (@15) $default reduce using rule 41 (comandos) comando_composto go to state 44 @@ -626,7 +641,7 @@ state 34 escrita go to state 50 numero go to state 51 comando_repetitivo go to state 52 - @14 go to state 53 + @15 go to state 53 comando_condicional go to state 54 if_then go to state 55 @@ -676,7 +691,7 @@ state 39 state 40 - 87 if_then: IF . expressao @16 THEN comando_sem_rotulo + 92 if_then: IF . expressao @17 THEN comando_sem_rotulo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 @@ -689,21 +704,21 @@ state 40 state 41 - 79 numero: NUMERO . + 84 numero: NUMERO . - $default reduce using rule 79 (numero) + $default reduce using rule 84 (numero) state 42 - 57 leitura: READ . ABRE_PARENTESES lista_leituras FECHA_PARENTESES + 62 leitura: READ . ABRE_PARENTESES lista_leituras FECHA_PARENTESES ABRE_PARENTESES shift, and go to state 68 state 43 - 61 escrita: WRITE . ABRE_PARENTESES lista_escritas FECHA_PARENTESES + 66 escrita: WRITE . ABRE_PARENTESES lista_escritas FECHA_PARENTESES ABRE_PARENTESES shift, and go to state 69 @@ -774,7 +789,7 @@ state 52 state 53 - 82 comando_repetitivo: @14 . WHILE expressao DO @15 comando_sem_rotulo + 87 comando_repetitivo: @15 . WHILE expressao DO @16 comando_sem_rotulo WHILE shift, and go to state 73 @@ -788,11 +803,11 @@ state 54 state 55 - 83 comando_condicional: if_then . cond_else + 88 comando_condicional: if_then . cond_else ELSE shift, and go to state 74 - $default reduce using rule 85 (cond_else) + $default reduce using rule 90 (cond_else) cond_else go to state 75 @@ -841,100 +856,101 @@ state 61 51 atribuicao_ou_procedimento: IDENT @12 . atribuicao_ou_procedimento_token ATRIBUICAO reduce using rule 54 (@13) - $default reduce using rule 56 (chamada_procedimento) + $default reduce using rule 56 (@14) atribuicao_ou_procedimento_token go to state 79 atribuicao go to state 80 @13 go to state 81 chamada_procedimento go to state 82 + @14 go to state 83 state 62 - 77 fator: IDENT . + 82 fator: IDENT . - $default reduce using rule 77 (fator) + $default reduce using rule 82 (fator) state 63 - 78 fator: NUMERO . + 83 fator: NUMERO . - $default reduce using rule 78 (fator) + $default reduce using rule 83 (fator) state 64 - 64 expressao: expressao . IGUAL expressao_simples - 65 | expressao . DIFERENTE expressao_simples - 66 | expressao . MENOR expressao_simples - 67 | expressao . MENOR_IGUAL expressao_simples - 68 | expressao . MAIOR expressao_simples - 69 | expressao . MAIOR_IGUAL expressao_simples - 87 if_then: IF expressao . @16 THEN comando_sem_rotulo - - IGUAL shift, and go to state 83 - DIFERENTE shift, and go to state 84 - MENOR_IGUAL shift, and go to state 85 - MAIOR_IGUAL shift, and go to state 86 - MENOR shift, and go to state 87 - MAIOR shift, and go to state 88 + 69 expressao: expressao . IGUAL expressao_simples + 70 | expressao . DIFERENTE expressao_simples + 71 | expressao . MENOR expressao_simples + 72 | expressao . MENOR_IGUAL expressao_simples + 73 | expressao . MAIOR expressao_simples + 74 | expressao . MAIOR_IGUAL expressao_simples + 92 if_then: IF expressao . @17 THEN comando_sem_rotulo - $default reduce using rule 86 (@16) + IGUAL shift, and go to state 84 + DIFERENTE shift, and go to state 85 + MENOR_IGUAL shift, and go to state 86 + MAIOR_IGUAL shift, and go to state 87 + MENOR shift, and go to state 88 + MAIOR shift, and go to state 89 - @16 go to state 89 + $default reduce using rule 91 (@17) + + @17 go to state 90 state 65 - 70 expressao: expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 75 expressao: expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 - $default reduce using rule 70 (expressao) + $default reduce using rule 75 (expressao) state 66 - 73 expressao_simples: termo . - 74 termo: termo . ASTERISCO fator - 75 | termo . DIV fator + 78 expressao_simples: termo . + 79 termo: termo . ASTERISCO fator + 80 | termo . DIV fator - DIV shift, and go to state 92 - ASTERISCO shift, and go to state 93 + DIV shift, and go to state 93 + ASTERISCO shift, and go to state 94 - $default reduce using rule 73 (expressao_simples) + $default reduce using rule 78 (expressao_simples) state 67 - 76 termo: fator . + 81 termo: fator . - $default reduce using rule 76 (termo) + $default reduce using rule 81 (termo) state 68 - 57 leitura: READ ABRE_PARENTESES . lista_leituras FECHA_PARENTESES + 62 leitura: READ ABRE_PARENTESES . lista_leituras FECHA_PARENTESES - IDENT shift, and go to state 94 + IDENT shift, and go to state 95 - lista_leituras go to state 95 - simb_leitura go to state 96 + lista_leituras go to state 96 + simb_leitura go to state 97 state 69 - 61 escrita: WRITE ABRE_PARENTESES . lista_escritas FECHA_PARENTESES + 66 escrita: WRITE ABRE_PARENTESES . lista_escritas FECHA_PARENTESES IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - lista_escritas go to state 97 - expressao_simples go to state 98 + lista_escritas go to state 98 + expressao_simples go to state 99 termo go to state 66 fator go to state 67 @@ -960,11 +976,11 @@ state 71 T_END reduce using rule 40 (comandos) T_END [reduce using rule 41 (comandos)] - WHILE reduce using rule 80 (@14) + WHILE reduce using rule 85 (@15) $default reduce using rule 40 (comandos) comando_composto go to state 44 - comandos go to state 99 + comandos go to state 100 comando go to state 46 comando_sem_rotulo go to state 47 atribuicao_ou_procedimento go to state 48 @@ -972,7 +988,7 @@ state 71 escrita go to state 50 numero go to state 51 comando_repetitivo go to state 52 - @14 go to state 53 + @15 go to state 53 comando_condicional go to state 54 if_then go to state 55 @@ -987,27 +1003,27 @@ state 72 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 80 (@14) + $default reduce using rule 85 (@15) comando_composto go to state 44 - comando_sem_rotulo go to state 100 + comando_sem_rotulo go to state 101 atribuicao_ou_procedimento go to state 48 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @14 go to state 53 + @15 go to state 53 comando_condicional go to state 54 if_then go to state 55 state 73 - 82 comando_repetitivo: @14 WHILE . expressao DO @15 comando_sem_rotulo + 87 comando_repetitivo: @15 WHILE . expressao DO @16 comando_sem_rotulo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao go to state 101 + expressao go to state 102 expressao_simples go to state 65 termo go to state 66 fator go to state 67 @@ -1015,7 +1031,7 @@ state 73 state 74 - 84 cond_else: ELSE . comando_sem_rotulo + 89 cond_else: ELSE . comando_sem_rotulo T_BEGIN shift, and go to state 34 IDENT shift, and go to state 39 @@ -1023,31 +1039,31 @@ state 74 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 80 (@14) + $default reduce using rule 85 (@15) comando_composto go to state 44 - comando_sem_rotulo go to state 102 + comando_sem_rotulo go to state 103 atribuicao_ou_procedimento go to state 48 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @14 go to state 53 + @15 go to state 53 comando_condicional go to state 54 if_then go to state 55 state 75 - 83 comando_condicional: if_then cond_else . + 88 comando_condicional: if_then cond_else . - $default reduce using rule 83 (comando_condicional) + $default reduce using rule 88 (comando_condicional) state 76 16 declara_var: @5 lista_id_var DOIS_PONTOS tipo @6 . PONTO_E_VIRGULA - PONTO_E_VIRGULA shift, and go to state 103 + PONTO_E_VIRGULA shift, and go to state 104 state 77 @@ -1056,9 +1072,9 @@ state 77 $default reduce using rule 33 (@11) - paramentros_formais go to state 104 - secao_pfs go to state 105 - @11 go to state 106 + paramentros_formais go to state 105 + secao_pfs go to state 106 + @11 go to state 107 state 78 @@ -1069,7 +1085,7 @@ state 78 $default reduce using rule 7 (parte_declara_rotulos) - bloco go to state 107 + bloco go to state 108 parte_declara_rotulos go to state 15 @@ -1091,7 +1107,7 @@ state 81 55 atribuicao: @13 . ATRIBUICAO expressao_simples - ATRIBUICAO shift, and go to state 108 + ATRIBUICAO shift, and go to state 109 state 82 @@ -1103,341 +1119,372 @@ state 82 state 83 - 64 expressao: expressao IGUAL . expressao_simples + 57 chamada_procedimento: @14 . lista_parametros - IDENT shift, and go to state 62 - NUMERO shift, and go to state 63 + ABRE_PARENTESES shift, and go to state 110 - expressao_simples go to state 109 - termo go to state 66 - fator go to state 67 + $default reduce using rule 59 (lista_parametros) + + lista_parametros go to state 111 state 84 - 65 expressao: expressao DIFERENTE . expressao_simples + 69 expressao: expressao IGUAL . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao_simples go to state 110 + expressao_simples go to state 112 termo go to state 66 fator go to state 67 state 85 - 67 expressao: expressao MENOR_IGUAL . expressao_simples + 70 expressao: expressao DIFERENTE . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao_simples go to state 111 + expressao_simples go to state 113 termo go to state 66 fator go to state 67 state 86 - 69 expressao: expressao MAIOR_IGUAL . expressao_simples + 72 expressao: expressao MENOR_IGUAL . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao_simples go to state 112 + expressao_simples go to state 114 termo go to state 66 fator go to state 67 state 87 - 66 expressao: expressao MENOR . expressao_simples + 74 expressao: expressao MAIOR_IGUAL . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao_simples go to state 113 + expressao_simples go to state 115 termo go to state 66 fator go to state 67 state 88 - 68 expressao: expressao MAIOR . expressao_simples + 71 expressao: expressao MENOR . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao_simples go to state 114 + expressao_simples go to state 116 termo go to state 66 fator go to state 67 state 89 - 87 if_then: IF expressao @16 . THEN comando_sem_rotulo + 73 expressao: expressao MAIOR . expressao_simples + + IDENT shift, and go to state 62 + NUMERO shift, and go to state 63 - THEN shift, and go to state 115 + expressao_simples go to state 117 + termo go to state 66 + fator go to state 67 state 90 - 71 expressao_simples: expressao_simples MAIS . termo + 92 if_then: IF expressao @17 . THEN comando_sem_rotulo - IDENT shift, and go to state 62 - NUMERO shift, and go to state 63 - - termo go to state 116 - fator go to state 67 + THEN shift, and go to state 118 state 91 - 72 expressao_simples: expressao_simples MENOS . termo + 76 expressao_simples: expressao_simples MAIS . termo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - termo go to state 117 + termo go to state 119 fator go to state 67 state 92 - 75 termo: termo DIV . fator + 77 expressao_simples: expressao_simples MENOS . termo IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - fator go to state 118 + termo go to state 120 + fator go to state 67 state 93 - 74 termo: termo ASTERISCO . fator + 80 termo: termo DIV . fator IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - fator go to state 119 + fator go to state 121 state 94 - 60 simb_leitura: IDENT . + 79 termo: termo ASTERISCO . fator + + IDENT shift, and go to state 62 + NUMERO shift, and go to state 63 - $default reduce using rule 60 (simb_leitura) + fator go to state 122 state 95 - 57 leitura: READ ABRE_PARENTESES lista_leituras . FECHA_PARENTESES - 58 lista_leituras: lista_leituras . VIRGULA simb_leitura + 65 simb_leitura: IDENT . - FECHA_PARENTESES shift, and go to state 120 - VIRGULA shift, and go to state 121 + $default reduce using rule 65 (simb_leitura) state 96 - 59 lista_leituras: simb_leitura . + 62 leitura: READ ABRE_PARENTESES lista_leituras . FECHA_PARENTESES + 63 lista_leituras: lista_leituras . VIRGULA simb_leitura - $default reduce using rule 59 (lista_leituras) + FECHA_PARENTESES shift, and go to state 123 + VIRGULA shift, and go to state 124 state 97 - 61 escrita: WRITE ABRE_PARENTESES lista_escritas . FECHA_PARENTESES - 62 lista_escritas: lista_escritas . VIRGULA expressao_simples + 64 lista_leituras: simb_leitura . - FECHA_PARENTESES shift, and go to state 122 - VIRGULA shift, and go to state 123 + $default reduce using rule 64 (lista_leituras) state 98 - 63 lista_escritas: expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 66 escrita: WRITE ABRE_PARENTESES lista_escritas . FECHA_PARENTESES + 67 lista_escritas: lista_escritas . VIRGULA expressao_simples - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 - - $default reduce using rule 63 (lista_escritas) + FECHA_PARENTESES shift, and go to state 125 + VIRGULA shift, and go to state 126 state 99 - 39 comandos: comando PONTO_E_VIRGULA comandos . + 68 lista_escritas: expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo - $default reduce using rule 39 (comandos) + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 68 (lista_escritas) state 100 - 42 comando: numero DOIS_PONTOS comando_sem_rotulo . + 39 comandos: comando PONTO_E_VIRGULA comandos . - $default reduce using rule 42 (comando) + $default reduce using rule 39 (comandos) state 101 - 64 expressao: expressao . IGUAL expressao_simples - 65 | expressao . DIFERENTE expressao_simples - 66 | expressao . MENOR expressao_simples - 67 | expressao . MENOR_IGUAL expressao_simples - 68 | expressao . MAIOR expressao_simples - 69 | expressao . MAIOR_IGUAL expressao_simples - 82 comando_repetitivo: @14 WHILE expressao . DO @15 comando_sem_rotulo + 42 comando: numero DOIS_PONTOS comando_sem_rotulo . - DO shift, and go to state 124 - IGUAL shift, and go to state 83 - DIFERENTE shift, and go to state 84 - MENOR_IGUAL shift, and go to state 85 - MAIOR_IGUAL shift, and go to state 86 - MENOR shift, and go to state 87 - MAIOR shift, and go to state 88 + $default reduce using rule 42 (comando) state 102 - 84 cond_else: ELSE comando_sem_rotulo . + 69 expressao: expressao . IGUAL expressao_simples + 70 | expressao . DIFERENTE expressao_simples + 71 | expressao . MENOR expressao_simples + 72 | expressao . MENOR_IGUAL expressao_simples + 73 | expressao . MAIOR expressao_simples + 74 | expressao . MAIOR_IGUAL expressao_simples + 87 comando_repetitivo: @15 WHILE expressao . DO @16 comando_sem_rotulo - $default reduce using rule 84 (cond_else) + DO shift, and go to state 127 + IGUAL shift, and go to state 84 + DIFERENTE shift, and go to state 85 + MENOR_IGUAL shift, and go to state 86 + MAIOR_IGUAL shift, and go to state 87 + MENOR shift, and go to state 88 + MAIOR shift, and go to state 89 state 103 + 89 cond_else: ELSE comando_sem_rotulo . + + $default reduce using rule 89 (cond_else) + + +state 104 + 16 declara_var: @5 lista_id_var DOIS_PONTOS tipo @6 PONTO_E_VIRGULA . $default reduce using rule 16 (declara_var) -state 104 +state 105 29 parametros_ou_nada: ABRE_PARENTESES @9 paramentros_formais . @10 FECHA_PARENTESES 32 paramentros_formais: paramentros_formais . PONTO_E_VIRGULA secao_pfs - PONTO_E_VIRGULA shift, and go to state 125 + PONTO_E_VIRGULA shift, and go to state 128 $default reduce using rule 28 (@10) - @10 go to state 126 + @10 go to state 129 -state 105 +state 106 31 paramentros_formais: secao_pfs . $default reduce using rule 31 (paramentros_formais) -state 106 +state 107 34 secao_pfs: @11 . lista_id_pf DOIS_PONTOS tipo - IDENT shift, and go to state 127 + IDENT shift, and go to state 130 - lista_id_pf go to state 128 - parametro go to state 129 + lista_id_pf go to state 131 + parametro go to state 132 -state 107 +state 108 26 declaracao_procedimento: PROCEDURE IDENT @7 parametros_ou_nada PONTO_E_VIRGULA bloco . @8 PONTO_E_VIRGULA $default reduce using rule 25 (@8) - @8 go to state 130 + @8 go to state 133 -state 108 +state 109 55 atribuicao: @13 ATRIBUICAO . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao_simples go to state 131 + expressao_simples go to state 134 termo go to state 66 fator go to state 67 -state 109 - - 64 expressao: expressao IGUAL expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo - - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 - - $default reduce using rule 64 (expressao) - - state 110 - 65 expressao: expressao DIFERENTE expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 58 lista_parametros: ABRE_PARENTESES . lista_parametros_parenteses FECHA_PARENTESES - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 + IDENT shift, and go to state 62 + NUMERO shift, and go to state 63 - $default reduce using rule 65 (expressao) + lista_parametros_parenteses go to state 135 + expressao_simples go to state 136 + termo go to state 66 + fator go to state 67 state 111 - 67 expressao: expressao MENOR_IGUAL expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 57 chamada_procedimento: @14 lista_parametros . - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 - - $default reduce using rule 67 (expressao) + $default reduce using rule 57 (chamada_procedimento) state 112 - 69 expressao: expressao MAIOR_IGUAL expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 69 expressao: expressao IGUAL expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 $default reduce using rule 69 (expressao) state 113 - 66 expressao: expressao MENOR expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 70 expressao: expressao DIFERENTE expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 - $default reduce using rule 66 (expressao) + $default reduce using rule 70 (expressao) state 114 - 68 expressao: expressao MAIOR expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 72 expressao: expressao MENOR_IGUAL expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 - $default reduce using rule 68 (expressao) + $default reduce using rule 72 (expressao) state 115 - 87 if_then: IF expressao @16 THEN . comando_sem_rotulo + 74 expressao: expressao MAIOR_IGUAL expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo + + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 74 (expressao) + + +state 116 + + 71 expressao: expressao MENOR expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo + + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 71 (expressao) + + +state 117 + + 73 expressao: expressao MAIOR expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo + + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 73 (expressao) + + +state 118 + + 92 if_then: IF expressao @17 THEN . comando_sem_rotulo T_BEGIN shift, and go to state 34 IDENT shift, and go to state 39 @@ -1445,190 +1492,211 @@ state 115 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 80 (@14) + $default reduce using rule 85 (@15) comando_composto go to state 44 - comando_sem_rotulo go to state 132 + comando_sem_rotulo go to state 137 atribuicao_ou_procedimento go to state 48 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @14 go to state 53 + @15 go to state 53 comando_condicional go to state 54 if_then go to state 55 -state 116 +state 119 - 71 expressao_simples: expressao_simples MAIS termo . - 74 termo: termo . ASTERISCO fator - 75 | termo . DIV fator + 76 expressao_simples: expressao_simples MAIS termo . + 79 termo: termo . ASTERISCO fator + 80 | termo . DIV fator - DIV shift, and go to state 92 - ASTERISCO shift, and go to state 93 + DIV shift, and go to state 93 + ASTERISCO shift, and go to state 94 - $default reduce using rule 71 (expressao_simples) + $default reduce using rule 76 (expressao_simples) -state 117 +state 120 - 72 expressao_simples: expressao_simples MENOS termo . - 74 termo: termo . ASTERISCO fator - 75 | termo . DIV fator + 77 expressao_simples: expressao_simples MENOS termo . + 79 termo: termo . ASTERISCO fator + 80 | termo . DIV fator - DIV shift, and go to state 92 - ASTERISCO shift, and go to state 93 + DIV shift, and go to state 93 + ASTERISCO shift, and go to state 94 - $default reduce using rule 72 (expressao_simples) + $default reduce using rule 77 (expressao_simples) -state 118 +state 121 - 75 termo: termo DIV fator . + 80 termo: termo DIV fator . - $default reduce using rule 75 (termo) + $default reduce using rule 80 (termo) -state 119 +state 122 - 74 termo: termo ASTERISCO fator . + 79 termo: termo ASTERISCO fator . - $default reduce using rule 74 (termo) + $default reduce using rule 79 (termo) -state 120 +state 123 - 57 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES . + 62 leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES . - $default reduce using rule 57 (leitura) + $default reduce using rule 62 (leitura) -state 121 +state 124 - 58 lista_leituras: lista_leituras VIRGULA . simb_leitura + 63 lista_leituras: lista_leituras VIRGULA . simb_leitura - IDENT shift, and go to state 94 + IDENT shift, and go to state 95 - simb_leitura go to state 133 + simb_leitura go to state 138 -state 122 +state 125 - 61 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES . + 66 escrita: WRITE ABRE_PARENTESES lista_escritas FECHA_PARENTESES . - $default reduce using rule 61 (escrita) + $default reduce using rule 66 (escrita) -state 123 +state 126 - 62 lista_escritas: lista_escritas VIRGULA . expressao_simples + 67 lista_escritas: lista_escritas VIRGULA . expressao_simples IDENT shift, and go to state 62 NUMERO shift, and go to state 63 - expressao_simples go to state 134 + expressao_simples go to state 139 termo go to state 66 fator go to state 67 -state 124 +state 127 - 82 comando_repetitivo: @14 WHILE expressao DO . @15 comando_sem_rotulo + 87 comando_repetitivo: @15 WHILE expressao DO . @16 comando_sem_rotulo - $default reduce using rule 81 (@15) + $default reduce using rule 86 (@16) - @15 go to state 135 + @16 go to state 140 -state 125 +state 128 32 paramentros_formais: paramentros_formais PONTO_E_VIRGULA . secao_pfs $default reduce using rule 33 (@11) - secao_pfs go to state 136 - @11 go to state 106 + secao_pfs go to state 141 + @11 go to state 107 -state 126 +state 129 29 parametros_ou_nada: ABRE_PARENTESES @9 paramentros_formais @10 . FECHA_PARENTESES - FECHA_PARENTESES shift, and go to state 137 + FECHA_PARENTESES shift, and go to state 142 -state 127 +state 130 37 parametro: IDENT . $default reduce using rule 37 (parametro) -state 128 +state 131 34 secao_pfs: @11 lista_id_pf . DOIS_PONTOS tipo - DOIS_PONTOS shift, and go to state 138 + DOIS_PONTOS shift, and go to state 143 -state 129 +state 132 35 lista_id_pf: parametro . VIRGULA lista_id_pf 36 | parametro . - VIRGULA shift, and go to state 139 + VIRGULA shift, and go to state 144 $default reduce using rule 36 (lista_id_pf) -state 130 +state 133 26 declaracao_procedimento: PROCEDURE IDENT @7 parametros_ou_nada PONTO_E_VIRGULA bloco @8 . PONTO_E_VIRGULA - PONTO_E_VIRGULA shift, and go to state 140 + PONTO_E_VIRGULA shift, and go to state 145 -state 131 +state 134 55 atribuicao: @13 ATRIBUICAO expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 $default reduce using rule 55 (atribuicao) -state 132 +state 135 - 87 if_then: IF expressao @16 THEN comando_sem_rotulo . + 58 lista_parametros: ABRE_PARENTESES lista_parametros_parenteses . FECHA_PARENTESES + 60 lista_parametros_parenteses: lista_parametros_parenteses . VIRGULA expressao_simples - $default reduce using rule 87 (if_then) + FECHA_PARENTESES shift, and go to state 146 + VIRGULA shift, and go to state 147 -state 133 +state 136 - 58 lista_leituras: lista_leituras VIRGULA simb_leitura . + 61 lista_parametros_parenteses: expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo - $default reduce using rule 58 (lista_leituras) + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + $default reduce using rule 61 (lista_parametros_parenteses) -state 134 - 62 lista_escritas: lista_escritas VIRGULA expressao_simples . - 71 expressao_simples: expressao_simples . MAIS termo - 72 | expressao_simples . MENOS termo +state 137 + + 92 if_then: IF expressao @17 THEN comando_sem_rotulo . - MAIS shift, and go to state 90 - MENOS shift, and go to state 91 + $default reduce using rule 92 (if_then) - $default reduce using rule 62 (lista_escritas) +state 138 -state 135 + 63 lista_leituras: lista_leituras VIRGULA simb_leitura . - 82 comando_repetitivo: @14 WHILE expressao DO @15 . comando_sem_rotulo + $default reduce using rule 63 (lista_leituras) + + +state 139 + + 67 lista_escritas: lista_escritas VIRGULA expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo + + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 67 (lista_escritas) + + +state 140 + + 87 comando_repetitivo: @15 WHILE expressao DO @16 . comando_sem_rotulo T_BEGIN shift, and go to state 34 IDENT shift, and go to state 39 @@ -1636,75 +1704,106 @@ state 135 READ shift, and go to state 42 WRITE shift, and go to state 43 - $default reduce using rule 80 (@14) + $default reduce using rule 85 (@15) comando_composto go to state 44 - comando_sem_rotulo go to state 141 + comando_sem_rotulo go to state 148 atribuicao_ou_procedimento go to state 48 leitura go to state 49 escrita go to state 50 comando_repetitivo go to state 52 - @14 go to state 53 + @15 go to state 53 comando_condicional go to state 54 if_then go to state 55 -state 136 +state 141 32 paramentros_formais: paramentros_formais PONTO_E_VIRGULA secao_pfs . $default reduce using rule 32 (paramentros_formais) -state 137 +state 142 29 parametros_ou_nada: ABRE_PARENTESES @9 paramentros_formais @10 FECHA_PARENTESES . $default reduce using rule 29 (parametros_ou_nada) -state 138 +state 143 34 secao_pfs: @11 lista_id_pf DOIS_PONTOS . tipo IDENT shift, and go to state 57 - tipo go to state 142 + tipo go to state 149 -state 139 +state 144 35 lista_id_pf: parametro VIRGULA . lista_id_pf - IDENT shift, and go to state 127 + IDENT shift, and go to state 130 - lista_id_pf go to state 143 - parametro go to state 129 + lista_id_pf go to state 150 + parametro go to state 132 -state 140 +state 145 26 declaracao_procedimento: PROCEDURE IDENT @7 parametros_ou_nada PONTO_E_VIRGULA bloco @8 PONTO_E_VIRGULA . $default reduce using rule 26 (declaracao_procedimento) -state 141 +state 146 - 82 comando_repetitivo: @14 WHILE expressao DO @15 comando_sem_rotulo . + 58 lista_parametros: ABRE_PARENTESES lista_parametros_parenteses FECHA_PARENTESES . - $default reduce using rule 82 (comando_repetitivo) + $default reduce using rule 58 (lista_parametros) -state 142 +state 147 + + 60 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA . expressao_simples + + IDENT shift, and go to state 62 + NUMERO shift, and go to state 63 + + expressao_simples go to state 151 + termo go to state 66 + fator go to state 67 + + +state 148 + + 87 comando_repetitivo: @15 WHILE expressao DO @16 comando_sem_rotulo . + + $default reduce using rule 87 (comando_repetitivo) + + +state 149 34 secao_pfs: @11 lista_id_pf DOIS_PONTOS tipo . $default reduce using rule 34 (secao_pfs) -state 143 +state 150 35 lista_id_pf: parametro VIRGULA lista_id_pf . $default reduce using rule 35 (lista_id_pf) + + +state 151 + + 60 lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples . + 76 expressao_simples: expressao_simples . MAIS termo + 77 | expressao_simples . MENOS termo + + MAIS shift, and go to state 91 + MENOS shift, and go to state 92 + + $default reduce using rule 60 (lista_parametros_parenteses) diff --git a/compilador.y b/compilador.y index e83b328109978eecb7482e6d22f513f8631d3226..566bdbb6367c30e619242a3d2facb8c1ebd3c710 100644 --- a/compilador.y +++ b/compilador.y @@ -265,20 +265,39 @@ atribuicao: { }; -chamada_procedimento: { +chamada_procedimento: + { if (l_elem == NULL || l_elem->categ != PR) { yyerror("Procedimento não declarado"); } else { // Gera código para chamar o procedimento - char buffer[50]; - mostra_ts(ts); - sprintf(buffer, "CHPR %s,%d", l_elem->info.pr.rot, nivel_lexico); - geraCodigo(NULL, buffer); + empilha(l_elem->ident, proc); } + } + + lista_parametros + + { + char buffer[50]; + mostra_ts(ts); + desempilha(buffer, proc); + l_elem = busca(buffer, ts); + sprintf(buffer, "CHPR %s,%d", l_elem->info.pr.rot, nivel_lexico); + geraCodigo(NULL, buffer); } ; +lista_parametros: ABRE_PARENTESES + lista_parametros_parenteses + FECHA_PARENTESES + | +; + +lista_parametros_parenteses: lista_parametros_parenteses VIRGULA expressao_simples + | expressao_simples +; + leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES ; diff --git a/teste8.pas b/teste8.pas new file mode 100644 index 0000000000000000000000000000000000000000..e0df5efd42e42a6a1eae5024827331c9d1c42da5 --- /dev/null +++ b/teste8.pas @@ -0,0 +1,11 @@ +program proc1 (input, output); + var x: integer; + procedure p(a, b: integer); + var z: integer; + begin + z := a; + end; +begin + x := 8; + p(x, 2); +end. \ No newline at end of file