Skip to content
Snippets Groups Projects
Commit 1a93ea1f authored by Henrique Margotte's avatar Henrique Margotte
Browse files

chama procedimento funcionando

parent 616ffbe1
No related branches found
No related tags found
No related merge requests found
......@@ -11,3 +11,6 @@ R02: NADA
R00: NADA
CRCT 8
ARMZ 0,0
CHPR R01,0
DMEM 0
PARA
This diff is collapsed.
......@@ -161,7 +161,7 @@ declaracao_procedimento: PROCEDURE IDENT {
char r_proc[4];
sprintf(r_proc, "R%02d", rot_id);
rot_id += 1;
info.pr.rot = r_proc;
strcpy(info.pr.rot,r_proc);
info.pr.quant = 0;
info.pr.param = NULL;
......@@ -196,27 +196,49 @@ comando: numero DOIS_PONTOS comando_sem_rotulo
| comando_sem_rotulo
;
comando_sem_rotulo: atribuicao
comando_sem_rotulo: atribuicao_ou_procedimento
| comando_composto
| comando_condicional
| comando_repetitivo
| leitura
| escrita
;
atribuicao_ou_procedimento: IDENT {l_elem = busca(token, ts);}
atribuicao_ou_procedimento_token
;
atribuicao_ou_procedimento_token: atribuicao
| chamada_procedimento
;
chamada_procedimento: /*IDENT {
l_elem = busca(token,ts);
atribuicao: {
if (l_elem == NULL) {
yyerror("Variável de destino não declarada");
} else {
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);
geraCodigo(NULL, buffer);
};
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);
}
//ABRE_PARENTESES FECHA_PARENTESES
}*/
}
;
leitura: READ ABRE_PARENTESES lista_leituras FECHA_PARENTESES
......@@ -285,24 +307,6 @@ termo: termo ASTERISCO fator {
| fator
;
atribuicao: IDENT {
mostra_ts(ts);
// Busca variável no lado esquerdo
l_elem = busca(token, ts);
if (l_elem == NULL) {
yyerror("Variável de destino não declarada");
} else {
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);
geraCodigo(NULL, buffer);
};
fator: IDENT {
// Carrega variável
l_elem = busca(token, ts);
......
......@@ -7,5 +7,5 @@ program proc1 (input, output);
end
begin
x := 8;
p
p;
end.
\ No newline at end of file
......@@ -20,7 +20,7 @@ void insere_ts(char *ident, int categ, int nivel, info_t info, ts_t *ts){
new->info.vs.tipo = info.vs.tipo;
new->info.vs.desloc = info.vs.desloc;
} else if (categ == PR) {
new->info.pr.rot = info.pr.rot;
strcpy(new->info.pr.rot, info.pr.rot);
new->info.pr.quant = info.pr.quant;
new->info.pr.param = (int **)malloc(info.pr.quant * sizeof(int *));
for (int i = 0; i < info.pr.quant; i++) {
......
......@@ -7,7 +7,7 @@ typedef struct vs_t {
} vs_t;
typedef struct pr_t {
char *rot;
char rot[4];
int quant;
int **param;
} pr_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment