Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sorry pelo atraso. Para teres linha e coluna nos ids e nas calls, tens que fazer as seguintes alterações (e são bastantes, eu avisei):
- **gocompiler.l**
- {ID} {if(flag==1)
- printf("ID(%s)\n", yytext);
- tok *ken = malloc(sizeof(tok));
- ken->line = num_linha;
- ken->col = num_coluna;
- ken->name = (char *) strdup(yytext);
- yylval.tok = ken;
- num_coluna+=yyleng;
- error_col=num_coluna;error_line=num_linha;
- last_token = "ID";
- if(flag==2) return ID;}
- Nota: Quando for preciso linha/coluna nos operadores vai ser necessário mudar essas funções no Lex também.
- **gocompiler.y**
- Alterar o tipo de token do Id para <tok> em vez de <cval>.
- Todas as funçoes que tiverem create_node("Id", registo_do_id); têm que ser alteradas para create_node2("Id",registo_do_id,registo_do_id->line,registo_do_id->col);
- %union{
- char *cval;
- struct _node *no;
- struct tok *tok;
- };
- **arvores.c (e .h)**
- node* create_node_timestamp(char* type, tok *id, int line, int col){
- node *aux = (node*)malloc(sizeof(node));
- aux->type = (char*)malloc(20*sizeof(char));
- aux->id = (char*)malloc(100*sizeof(char));
- strcpy(aux->type,type);
- if (id==NULL){
- strcpy(aux->id,"NULL");
- } else {
- strcpy(aux->id,id->name);
- }
- strcpy(aux->annotate, "NULL");
- aux->child = NULL;
- aux->brother = NULL;
- aux->line = line;
- aux->col = col;
- return aux;
- }
- **tables.c (e .h)**
- Alterar a função add para receber o nó da árvore no final e adicionar as seguintes linhas de código ao final:
- this->line = no->line;
- this->col = no->col;
- Todas as instâncias da função Add têm que ser atualizadas.
- **structures.h**
- typedef struct _node{
- char* type;
- char* id;
- char annotate[256];
- struct _node *child;
- struct _node *brother;
- int line;
- int col;
- }node;
- typedef struct tok{
- char *name;
- int line;
- int col;
- }tok;
- typedef struct telem{
- char name[1024];
- char type[1024];
- char param[6];
- int func;
- int visited;
- int line;
- int col;
- struct telem *next;
- } table_element;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement