Advertisement
Guest User

370p2l error checking

a guest
Oct 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. //errors to check for
  2. //duplicate defined global labels
  3. //stack label defined by an object file
  4. //undefined global symbol
  5. int numFiles = argc - 2;
  6. for(int i = 0; i < numFiles; i++)//loop over each file
  7. {
  8.     //check each global symbol
  9.     for(int j = 0; j < files[i].symbolTableSize; j++)
  10.     {
  11.         SymbolTableEntry globalSymbol = files[i].symbolTable[j];
  12.  
  13.         //check if stack is defined
  14.         if(strcmp(globalSymbol.label, "Stack") == 0 && globalSymbol.location != 'U')
  15.         {
  16.             printf("Symbol \'Stack\' defined locally\n");
  17.             return 1;
  18.         }
  19.  
  20.         if(globalSymbol.location != 'U')//check for duplicates
  21.         {
  22.             //loop over the other files
  23.             for(int k = 0; k < numFiles; k++)
  24.             {
  25.                 //loop over the global symbol file
  26.                 for(int l = 0; l < files[k].symbolTableSize; l++)
  27.                 {
  28.                     SymbolTableEntry otherGlobalSymbol = files[k].symbolTable[l];
  29.                     if(otherGlobalSymbol.location != 'U' && !((i == k) && (j == l)) && strcmp(globalSymbol.label, otherGlobalSymbol.label) == 0)
  30.                     {
  31.                         printf("Duplicate Global Symbol: %s\n", otherGlobalSymbol.label);
  32.                         return 1;
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.  
  38.         if(globalSymbol.location == 'U')//check if it's defined anywhere
  39.         {
  40.             int defined = 0;
  41.             //loop over the other files
  42.             for(int k = 0; k < numFiles; k++)
  43.             {
  44.                 //loop over the global symbol file
  45.                 for(int l = 0; l < files[k].symbolTableSize; l++)
  46.                 {
  47.                     SymbolTableEntry otherGlobalSymbol = files[k].symbolTable[l];
  48.                    
  49.                     //is this the definition?
  50.                     if(otherGlobalSymbol.location != 'U' && !((i == k) && (j == l)) && strcmp(globalSymbol.label, otherGlobalSymbol.label) == 0)
  51.                     {
  52.                         defined = 1;
  53.                     }
  54.                 }
  55.             }
  56.             if(defined == 0)
  57.             {
  58.                 printf("Undefined Global Symbol: %s\n", globalSymbol.label);
  59.                 return 1;
  60.             }
  61.         }
  62.     }
  63. }
  64. //finished checking for errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement