From 954fc6b9d4bfee8b2eb1af11f4e62a66b9e8da57 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 18 Apr 2024 18:00:40 -0300 Subject: finalizado? --- include/lexical.h | 14 +++++++++++++- include/map.h | 5 +++++ lexical.c | 19 ++++++++++++++++--- main | Bin 30352 -> 30792 bytes main.c | 23 +++++++++++++++++------ map.c | 5 +++++ txt.txt | 3 +-- 7 files changed, 57 insertions(+), 12 deletions(-) diff --git a/include/lexical.h b/include/lexical.h index a3168ef..040d383 100644 --- a/include/lexical.h +++ b/include/lexical.h @@ -1,3 +1,8 @@ +/* + * Nome: Leonardo Koosuke Azuma + * SO: Arch Linux x86_64 + * Compilador: gcc (GCC) 13.2.1 20230801 + */ #ifndef _MYLEX_H #define _MYLEX_H @@ -17,6 +22,13 @@ extern char proximo; extern int linha; extern int identificador_num; +extern FILE *fout; + +enum error_type{ + SIMBOLO_ESPECIAL_DESCONHECIDO, + IDENTIFICAR_NUMERO_MAL_FORMADO +}; + void init_special_char(); void init_simbolos_especiais(); void init_simbolos_especiais_compostos(); @@ -29,6 +41,6 @@ int is_numero(char tmp); void PROXIMO(FILE *fp); char* CODIGO(char *cod); -void ERRO(int error_code); +void ERRO(enum error_type error_code); #endif diff --git a/include/map.h b/include/map.h index 1dea3e7..b1f2650 100644 --- a/include/map.h +++ b/include/map.h @@ -1,3 +1,8 @@ +/* + * Nome: Leonardo Koosuke Azuma + * SO: Arch Linux x86_64 + * Compilador: gcc (GCC) 13.2.1 20230801 + */ #ifndef _MYMAP_H #define _MYMAP_H diff --git a/lexical.c b/lexical.c index 22d219b..b742311 100644 --- a/lexical.c +++ b/lexical.c @@ -1,3 +1,8 @@ +/* + * Nome: Leonardo Koosuke Azuma + * SO: Arch Linux x86_64 + * Compilador: gcc (GCC) 13.2.1 20230801 + */ #include #include #include "include/map.h" @@ -7,6 +12,8 @@ char proximo = '\n'; int is_EOF = 0; int linha = 1; // Numero da linha atual) int identificador_num = 1; + +FILE *fout; string_map special_char; string_map simbolos_especiais; @@ -88,9 +95,11 @@ void PROXIMO(FILE *fp){ } if(proximo == '\n'){ printf("\n"); + fprintf(fout, "\n"); PROXIMO(fp); linha++; printf("linha %d: ", linha); + fprintf(fout, "linha %d: ", linha); } return ; @@ -117,9 +126,13 @@ char* CODIGO(char *cod){ return NULL; } -void ERRO(int error_code){ +void ERRO(enum error_type error_code){ fprintf(stderr, "Erro na linha %d\n", linha); - if(error_code == 1) fprintf(stderr, "primerio erro\n"); - else fprintf(stderr, "segundo erro\n"); + if(error_code == SIMBOLO_ESPECIAL_DESCONHECIDO){ + fprintf(stderr, "ERRO: Simbolo especial desconhecido\n"); + } + else{ + fprintf(stderr, "ERRO: Identificador ou numero mal formado\n"); + } exit(1); } diff --git a/main b/main index 6eba4ba..807bdb1 100755 Binary files a/main and b/main differ diff --git a/main.c b/main.c index 50f5354..a87807d 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,8 @@ +/* + * Nome: Leonardo Koosuke Azuma + * SO: Arch Linux x86_64 + * Compilador: gcc (GCC) 13.2.1 20230801 + */ #include #include @@ -12,17 +17,19 @@ extern string_map simbolos_especiais_composto; extern string_map simbolos_especiais_composto_negrito; extern int is_EOF; +extern FILE *fout; int main(int argc, char *argv[]){ - /* - if(argc != 2){ + + if(argc != 2){ fprintf(stderr, "passe o nome do arquivo\n"); exit(EXT_ERR_PARAMS); - }*/ + } init_all_map(); - char *file_path = "txt.txt";//argv[1]; + char *file_path = argv[1]; FILE *fp = fopen(file_path, "r"); + fout = fopen("out.txt", "w"); extern char proximo; char *simbolo; @@ -31,10 +38,12 @@ int main(int argc, char *argv[]){ PROXIMO(fp); printf("linha 1: "); + fprintf(fout, "linha 1: "); while(is_EOF == 0){ while(proximo == ' ' || proximo == '\t' || proximo == '\r') PROXIMO(fp); while(proximo == '\n' && is_EOF != 1){ printf("\n"); + fprintf(fout, "\n"); PROXIMO(fp); } if(is_EOF) break; @@ -91,7 +100,7 @@ int main(int argc, char *argv[]){ atomo[indice] = '\0'; if(is_caracter(proximo)){ - ERRO(1); + ERRO(IDENTIFICAR_NUMERO_MAL_FORMADO); } char *tmpp; @@ -108,9 +117,10 @@ int main(int argc, char *argv[]){ // printf("ni: %s\n", ni); } }else{ - ERRO(2); + ERRO(SIMBOLO_ESPECIAL_DESCONHECIDO); } printf("%s ", simbolo); + fprintf(fout, "%s ", simbolo); } // printf("nu: %s\n", get_value("123123", simbolos_numeros)); @@ -118,6 +128,7 @@ int main(int argc, char *argv[]){ // printf("linha: %d\n", linha); fclose(fp); + fclose(fout); return 0; } diff --git a/map.c b/map.c index 39272fd..56a83d9 100644 --- a/map.c +++ b/map.c @@ -1,3 +1,8 @@ +/* + * Nome: Leonardo Koosuke Azuma + * SO: Arch Linux x86_64 + * Compilador: gcc (GCC) 13.2.1 20230801 + */ #include "include/map.h" #include #include diff --git a/txt.txt b/txt.txt index 48b0fbc..ef50ddb 100644 --- a/txt.txt +++ b/txt.txt @@ -1,8 +1,7 @@ - program exemplo1 - var + var n, s, i: integer; procedure soma; var q: integer; -- cgit v1.2.3