Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. void percorre_AST (n1 roots){
  2.     n1 root = roots;
  3.     int verificaIrmao = 1;
  4.     root =  root->filhos;
  5.     scope_Root = init_Scope("Global");
  6.     addPutcharGetChar();
  7.     while(verificaIrmao == 1){
  8.         if(strcmp(root->descricao,"VarDecl") == 0){
  9.             adiciona_VarDecl(root);
  10.         }
  11.         else if(strcmp(root->descricao,"FuncDecl") == 0){
  12.             if(checkFuncDecl(root->filhos->filhos->valor) == 0 && checkFuncInTable(root->filhos->filhos->valor) == 0){
  13.                 addFuncToGlogal(root);
  14.             }
  15.         }
  16.  
  17.         root=root->irmaos;
  18.         if(root==NULL){
  19.             verificaIrmao=0;
  20.         }
  21.  
  22.  
  23.     }
  24.     printScopes();
  25.     printf("\n");
  26.     //imprime_AST(roots,0);
  27.     imprime_AST_Anotada_Main(roots,0,"Program","Global");
  28. }
  29.  
  30.  
  31.  
  32. void adiciona_VarDecl(n1 var_decl_Root){
  33.     char* descricaoLower = NULL;
  34.     table_Pointer tableCur = scope_Root->tabelas;
  35.     if(checkVarDecl(var_decl_Root->filhos->irmaos->valor,scope_Root) == 0){
  36.         while(tableCur->next != NULL){
  37.             tableCur = tableCur->next;
  38.  
  39.         }
  40.         tableCur->next = init_Table(var_decl_Root->filhos->irmaos->valor);
  41.         descricaoLower = tornaPrimeiroCharEmLowerCase(var_decl_Root->filhos->descricao,descricaoLower);
  42.         tableCur->next->type = descricaoLower;
  43.         /*printf("%s\t%s\n",var_decl_Root->filhos->descricao,descricaoLower);*/
  44.         var_decl_Root->filhos->irmaos->type = descricaoLower;
  45.         tableCur->next->params = "VarDecl";
  46.     }
  47.     else{
  48.         printf("Line %d, column %d: Symbol %s already defined\n",var_decl_Root->filhos->irmaos->line,var_decl_Root->filhos->irmaos->coluna,var_decl_Root->filhos->irmaos->valor);
  49.     }
  50.     return;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement