Advertisement
Guest User

Como obter linha/coluna

a guest
May 24th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. 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):
  2.  
  3. **gocompiler.l**
  4.  
  5. {ID} {if(flag==1)
  6. printf("ID(%s)\n", yytext);
  7. tok *ken = malloc(sizeof(tok));
  8. ken->line = num_linha;
  9. ken->col = num_coluna;
  10. ken->name = (char *) strdup(yytext);
  11. yylval.tok = ken;
  12. num_coluna+=yyleng;
  13. error_col=num_coluna;error_line=num_linha;
  14. last_token = "ID";
  15. if(flag==2) return ID;}
  16.  
  17. Nota: Quando for preciso linha/coluna nos operadores vai ser necessário mudar essas funções no Lex também.
  18.  
  19. **gocompiler.y**
  20.  
  21. Alterar o tipo de token do Id para <tok> em vez de <cval>.
  22. 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);
  23.  
  24. %union{
  25. char *cval;
  26. struct _node *no;
  27. struct tok *tok;
  28. };
  29.  
  30. **arvores.c (e .h)**
  31.  
  32. node* create_node_timestamp(char* type, tok *id, int line, int col){
  33. node *aux = (node*)malloc(sizeof(node));
  34. aux->type = (char*)malloc(20*sizeof(char));
  35. aux->id = (char*)malloc(100*sizeof(char));
  36. strcpy(aux->type,type);
  37. if (id==NULL){
  38. strcpy(aux->id,"NULL");
  39. } else {
  40. strcpy(aux->id,id->name);
  41. }
  42. strcpy(aux->annotate, "NULL");
  43. aux->child = NULL;
  44. aux->brother = NULL;
  45. aux->line = line;
  46. aux->col = col;
  47. return aux;
  48. }
  49.  
  50. **tables.c (e .h)**
  51.  
  52. Alterar a função add para receber o nó da árvore no final e adicionar as seguintes linhas de código ao final:
  53. this->line = no->line;
  54. this->col = no->col;
  55.  
  56. Todas as instâncias da função Add têm que ser atualizadas.
  57.  
  58. **structures.h**
  59.  
  60. typedef struct _node{
  61. char* type;
  62. char* id;
  63. char annotate[256];
  64. struct _node *child;
  65. struct _node *brother;
  66. int line;
  67. int col;
  68. }node;
  69.  
  70. typedef struct tok{
  71. char *name;
  72. int line;
  73. int col;
  74. }tok;
  75.  
  76. typedef struct telem{
  77. char name[1024];
  78. char type[1024];
  79. char param[6];
  80. int func;
  81. int visited;
  82. int line;
  83. int col;
  84. struct telem *next;
  85. } table_element;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement