summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo <leo@azuminha.com>2024-04-18 18:00:40 -0300
committerleo <leo@azuminha.com>2024-04-18 18:00:40 -0300
commit954fc6b9d4bfee8b2eb1af11f4e62a66b9e8da57 (patch)
tree2e54bccfcb9507f4919b67ddb0a4996f91dd608c
parent0d530f0e84c15387cd22ae1608c284befff8e87f (diff)
finalizado?
-rw-r--r--include/lexical.h14
-rw-r--r--include/map.h5
-rw-r--r--lexical.c19
-rwxr-xr-xmainbin30352 -> 30792 bytes
-rw-r--r--main.c23
-rw-r--r--map.c5
-rw-r--r--txt.txt3
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 <stdio.h>
#include <stdlib.h>
#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
--- a/main
+++ b/main
Binary files 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 <stdio.h>
#include <stdlib.h>
@@ -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 <stdlib.h>
#include <stdio.h>
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;