Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //errors to check for
- //duplicate defined global labels
- //stack label defined by an object file
- //undefined global symbol
- int numFiles = argc - 2;
- for(int i = 0; i < numFiles; i++)//loop over each file
- {
- //check each global symbol
- for(int j = 0; j < files[i].symbolTableSize; j++)
- {
- SymbolTableEntry globalSymbol = files[i].symbolTable[j];
- //check if stack is defined
- if(strcmp(globalSymbol.label, "Stack") == 0 && globalSymbol.location != 'U')
- {
- printf("Symbol \'Stack\' defined locally\n");
- return 1;
- }
- if(globalSymbol.location != 'U')//check for duplicates
- {
- //loop over the other files
- for(int k = 0; k < numFiles; k++)
- {
- //loop over the global symbol file
- for(int l = 0; l < files[k].symbolTableSize; l++)
- {
- SymbolTableEntry otherGlobalSymbol = files[k].symbolTable[l];
- if(otherGlobalSymbol.location != 'U' && !((i == k) && (j == l)) && strcmp(globalSymbol.label, otherGlobalSymbol.label) == 0)
- {
- printf("Duplicate Global Symbol: %s\n", otherGlobalSymbol.label);
- return 1;
- }
- }
- }
- }
- if(globalSymbol.location == 'U')//check if it's defined anywhere
- {
- int defined = 0;
- //loop over the other files
- for(int k = 0; k < numFiles; k++)
- {
- //loop over the global symbol file
- for(int l = 0; l < files[k].symbolTableSize; l++)
- {
- SymbolTableEntry otherGlobalSymbol = files[k].symbolTable[l];
- //is this the definition?
- if(otherGlobalSymbol.location != 'U' && !((i == k) && (j == l)) && strcmp(globalSymbol.label, otherGlobalSymbol.label) == 0)
- {
- defined = 1;
- }
- }
- }
- if(defined == 0)
- {
- printf("Undefined Global Symbol: %s\n", globalSymbol.label);
- return 1;
- }
- }
- }
- }
- //finished checking for errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement