From d066e9b09d14cfcf3dd1b10f6e41fc77a9136b85 Mon Sep 17 00:00:00 2001
From: viniciusmioto <vsmioto@gmail.com>
Date: Mon, 2 Dec 2024 22:02:03 -0300
Subject: [PATCH] chamada de procedimentos completa

---
 MEPA         |  3 +--
 compilador.y | 13 ++++++++++---
 teste9.pas   |  2 +-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/MEPA b/MEPA
index ef04081..262e92e 100644
--- a/MEPA
+++ b/MEPA
@@ -14,8 +14,7 @@ R00: NADA
      CRCT 8
      ARMZ 0,0
      CREN 0,0
-     CRCT 2
-     SOMA
+     CRCT 8
      CRCT 2
      CRCT 3
      SOMA
diff --git a/compilador.y b/compilador.y
index d684230..654f76f 100644
--- a/compilador.y
+++ b/compilador.y
@@ -338,6 +338,7 @@ lista_parametros_parenteses: lista_parametros_parenteses VIRGULA
                expressao_simples
                {
                   num_param++; // Incrementa para cada parâmetro real
+                  val_ou_ref = VLR;
                }
                | {
                   char buffer[50];
@@ -349,6 +350,7 @@ lista_parametros_parenteses: lista_parametros_parenteses VIRGULA
                expressao_simples
                {
                   num_param++; // Conta o primeiro parâmetro real
+                  val_ou_ref = VLR;
                }
 ;
 
@@ -401,10 +403,16 @@ expressao: expressao IGUAL expressao_simples {
 ;
 
 expressao_simples: expressao_simples MAIS termo {
-               geraCodigo(NULL, "SOMA"); // Adiciona operação de soma
+               if (val_ou_ref == REF)
+                  yyerror("Erro: tentativa de EXPRESSAO em passagem por REFERENCIA\n");
+               else
+                  geraCodigo(NULL, "SOMA"); // Adiciona operação de soma
             }
             | expressao_simples MENOS termo {
-               geraCodigo(NULL, "SUBT"); // Adiciona operação de subt
+               if (val_ou_ref == REF)
+                  yyerror("Erro: tentativa de EXPRESSAO em passagem por REFERENCIA\n");
+               else
+                  geraCodigo(NULL, "SUBT"); // Adiciona operação de subt
             }
             | termo
 ;
@@ -435,7 +443,6 @@ fator: IDENT {
             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 5e3e87b..96ad049 100644
--- a/teste9.pas
+++ b/teste9.pas
@@ -8,5 +8,5 @@ program proc1 (input, output);
     end;
 begin
     x := 8;
-    p(x, 2+3);
+    p(x+9, 2+3);
 end.
\ No newline at end of file
-- 
GitLab