![]() |
| | #1 | |
| Registered User Join Date: May 2008
Posts: 20
| I'm developing a compiler and at this stage I'mhaving problems compiling one of the files ("tabela_simbolos.c"). Here's the .c and .h and the error messages: tabela_simbolos.c Code: #include "tabela_simbolos.h"
#include <malloc.h>
#include <string.h>
#include <stdio.h>
extern elemento_tabela* simbolo_tabela;
//Insere um novo identificador na cauda de uma lista ligada de símbolos
elemento_tabela *insere_elemento(char *str, tipo_basico t)
{
elemento_tabela *novo_simbolo=(elemento_tabela*) malloc(sizeof(elemento_tabela));
elemento_tabela *aux;
elemento_tabela* anterior;
strcpy(novo_simbolo->nome, str);
novo_simbolo->tipo=t;
novo_simbolo->proximo=NULL;
if(simbolo_tabela) //Se a tabela já tem elementos
{ //Procura cauda da lista e verifica se simbolo ja existe (NOTA: assume-se uma tabela de simbolos globais!)
for(aux=simbolo_tabela; aux; anterior=aux, aux=aux->proximo)
if(strcmp(aux->nome, str)==0)
return NULL;
anterior->proximo=novo_simbolo; //adiciona ao final da lista
}
else //simbolo_tabela tem um elemento -> o novo símbolo
simbolo_tabela=novo_simbolo;
return novo_simbolo;
}
void mostra_tabela()
{
elemento_tabela *aux;
printf("\n");
for(aux=simbolo_tabela; aux; aux=aux->proximo)
printf("símbolo %s, tipo %d\n", aux->nome, aux->tipo);
}
//Procura um identificador, devolve 0 caso não exista
elemento_tabela *procura_elemento(char *str)
{
elemento_tabela *aux;
for(aux=simbolo_tabela; aux; aux=aux->proximo)
if(strcmp(aux->nome, str)==0)
return aux;
return NULL;
}
Code: #ifndef TABELA_SIMBOLOS_H
#define TABELA_SIMBOLOS_H
typedef enum {INTEIRO, FLOAT, CARACTER} tipo_basico;
typedef struct _t1
{
char nome[32];
tipo_basico tipo;
struct _t1 *proximo;
} elemento_tabela;
elemento_tabela *insere_elemento(char *str, tipo_basico t);
void mostra_tabela();
elemento_tabela *procura_elemento(char *str);
#endif
Quote:
Many thanks, João Fernandes Last edited by blacknail; 09-13-2008 at 03:16 PM. | |
| blacknail is offline | |
| | #2 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| You have this: Code: extern elemento_tabela* simbolo_tabela; |
| tabstop is offline | |
| | #3 | |
| Registered User Join Date: May 2008
Posts: 20
| That was the problem... sorry :| But now I get the following error: Quote:
The code is as posted above or the following: Code: #ifndef TABELA_SIMBOLOS_H
#define TABELA_SIMBOLOS_H
typedef enum {INTEIRO, FLOAT, CARACTER} tipo_basico;
typedef struct _t1
{
char nome[32];
tipo_basico tipo;
struct _t1 *proximo;
} elemento_tabela;
elemento_tabela *insere_elemento(char *str, tipo_basico t);
void mostra_tabela();
elemento_tabela *procura_elemento(char *str);
#endif
Last edited by blacknail; 09-14-2008 at 04:15 PM. | |
| blacknail is offline | |
| | #4 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Well. I don't get that error, when I try to compile that file. Are one of INTEIRO, FLOAT, or CARACTER #defined somewhere else, perhaps? Somehow something on that line is apparently getting pre-processed into a number. |
| tabstop is offline | |
| | #5 |
| Registered User Join Date: May 2008
Posts: 20
| The weird stuff is that I also have no errors when compiling the file alone. but when I compile with the other files of the compiler that error appears... of course it must have to do with the other files but I don't know where it must be the problem :| |
| blacknail is offline | |
| | #6 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| I would look for those three words in your other files (maybe tipo_basico too). You could also add one file at a time to the project and see which one it's in. |
| tabstop is offline | |
| | #7 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| malloc is in stdlib.h, not malloc.h Also, see the FAQ on casting the result of malloc.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #8 |
| Registered User Join Date: May 2008
Posts: 20
| For me, the weirdest thing is this. The script I use for compiling is: Code: #!/bin/bash clear lex kpython.l yacc -d kpython.y gcc -o kpython lex.yy.c y.tab.c estruturas.h funcoes.c funcoes.h semantica.c semantica.h tabela_simbolos.c tabela_simbolos.h Code: #!/bin/bash clear lex kpython.l yacc -d kpython.y Last edited by blacknail; 09-15-2008 at 04:49 AM. |
| blacknail is offline | |
![]() |
| Tags |
| error, pointer, reference, undefined |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sorting number | Leslie | C Programming | 8 | 05-20-2009 04:23 AM |
| Double Pointer to a data type that is already a pointer! | nicm | C Programming | 5 | 04-04-2009 03:45 AM |
| Using Vectors. MinGW warning | Viewer | C++ Programming | 9 | 03-26-2009 03:15 PM |
| Strange/false errors | Ganoosh | Windows Programming | 8 | 10-20-2005 04:54 PM |
| C++ pointer vs reference | C-Dumbie | C++ Programming | 4 | 11-04-2002 04:08 AM |