From 4eba85d0bf620b2f488c2cbeee6a84b2e4bf9fbf Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 16 Apr 2024 21:18:24 -0300 Subject: AAAAAAAAAAAAAAAAAAAAAAAAAAAA --- main.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 122 insertions(+), 30 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 0f0d650..e0663a4 100644 --- a/main.c +++ b/main.c @@ -2,37 +2,129 @@ #include #include "include/map.h" +#include "include/lexical.h" #define EXT_ERR_PARAMS 1 + +extern string_map special_char; +extern string_map simbolos_especiais; +extern string_map simbolos_especiais_composto; +extern string_map simbolos_especiais_composto_negrito; + +extern int is_EOF; + int main(int argc, char *argv[]){ - string_map special_char = init_map(1024); - - insert_map("aa", "aa", special_char); - insert_map("d", "d", special_char); - - char *test = get_value("aa", special_char); - printf("%s\n", test); - test = get_value("d", special_char); - printf("%s\n", test); - test = get_value("d", special_char); - printf("%s\n", test); - test = get_value("aa", special_char); - printf("%s\n", test); - /* - if(argc != 2){ - fprintf(stderr, "passe o nome do arquivo\n"); - exit(EXT_ERR_PARAMS); - } - - char *file_path = argv[1]; - FILE *fp = fopen(file_path, "r"); - - char tmp; - while(fscanf(fp, "%c", &tmp) != EOF){ - printf("%c", tmp); - } - - fclose(fp); - */ - return 0; + /* + init_special_char(); + printf("%s\n", test); + init_simbolos_especiais(); + test = get_value("d", special_char); + printf("%s\n", test); + test = get_value("d", special_char); + printf("%s\n", test); + test = get_value("aa", special_char); + printf("%s\n", test); + */ + /* + 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]; + FILE *fp = fopen(file_path, "r"); + + extern char proximo; + char *simbolo; + char atomo[4096]; + + PROXIMO(fp); + while(proximo == '\n'){ + PROXIMO(fp); + } + + char tmp[2] = "\0"; tmp[0] = proximo; + if(get_value(tmp, simbolos_especiais) != NULL){ + char s[3] = "\0"; s[0] = proximo; + PROXIMO(fp); + + if(s[0] == ':' && proximo == '='){ + s[1] = '='; + } + simbolo = CODIGO(s); + }else if(is_caracter(proximo)){ + int indice = 0; + while(is_caracter(proximo) || is_numero(proximo)){ + atomo[indice++] = proximo; + PROXIMO(fp); + } + atomo[indice] = '\0'; + printf("atomo: %s\n", atomo); + + //se atomo pertence a palavra reservada + if(get_value(atomo, simbolos_especiais_composto_negrito) != NULL || + get_value(atomo, simbolos_identificadores) != NULL){ + simbolo = CODIGO(atomo); + }else{ + /* criar codigo identificador */ + char *ci = malloc(sizeof(char) * 256); + ci[0] = 'i'; ci[1] = 'd'; + + int _i = 2; + extern int identificador_num; + int aux = identificador_num++; + + while(aux > 0){ + int n = aux%10; + aux /= 10; + ci[_i++] = '0' + n; + } + ci[_i] = '\0'; + + simbolo = ci; + // printf("atomo: %s\t ci: %s\n", atomo, ci); + insert_map(atomo, ci, simbolos_identificadores); + } + }else if(is_numero(proximo)){ + int indice = 0; + while(is_numero(proximo)){ + atomo[indice++] = proximo; + PROXIMO(fp); + } + atomo[indice] = '\0'; + + if(is_caracter(proximo)){ + ERRO(); + } + + char *tmpp; + if((tmpp = get_value(atomo, simbolos_numeros)) != NULL){ + simbolo = tmpp; + }else{ + char *ni = malloc(sizeof(char) * 128); + ni[0] = 'n'; ni[1] = 'u'; ni[2] = 'm'; + for(int i=0; i<=strlen(atomo); ++i){ + ni[i+3] = atomo[i]; + } + simbolo = ni; + insert_map(atomo, ni, simbolos_numeros); +// printf("ni: %s\n", ni); + } + }else{ + ERRO(); + } + +// printf("nu: %s\n", get_value("123123", simbolos_numeros)); + + +// printf("linha: %d\n", linha); + /*while(is_EOF != 1){ + PROXIMO(fp); + printf("%c", proximo); + }*/ + + fclose(fp); + + return 0; } -- cgit v1.2.3