Hello and welcome.
In this lecture, we're going to discuss symbol resolution and resolving symbols.
So I know we recently implemented a scope system.
I wanted to go ahead and show us using that scope system.
But unfortunately, we're not at the stage in the course where we can use that just yet.
So we're going to implement a symbol resolver and we're going to go back to Scopes later in the course.
So what are symbols?
Symbols are functions we have identified during the compile process.
Symbols are structures we have identified during the compile process.
And finally, they're global variables.
When I talk about symbols, I'm not talking about symbols that you will find in an object file.
I'm talking about what our compiler considers symbols.
So our system needs to be able to register symbols when we encounter them, and it needs to be able
to fetch symbols by name, such as a structure, name, function name or global variable name.
So why do we need symbols when we go ahead and create a structure variable, obviously that has a structure
name for the type of structure we're trying to create.
If we don't register that structure somewhere, how are we to go and resolve what structure that that
variable ABC is using?
While we won't be able to, will we?
So we need to register all structures we encounter as in memory symbols, and then we can go through
our in memory symbol table and pull by the structure name when that structure is accessed.
So the same goes for functions that we call a function.
How are we to know that that function even exists if we don't keep track of the registered functions
during completion?
We need to keep track of all functions called and okay.
We might not define the function body in a particular source file, but obviously a prototype to that
function would be handy.
Right?
So we need to register all of this as symbols and global variables have to be treated as symbols because
other modules might access them.
You can have external variables, can't you?
External global variables.
So the rules for the symbols of are very simple.
They should never share the same name.
If we have a structure called struct dog, we can't have a function called dog.
So here's an illustration of the symbol table in action.
So we can see in our program we've registered a structure called ABC and a structure named Dog.
Ignore the missing semicolon.
So when we go struct ABC dx, what'll happen is it'll look through our symbol table and it will find
the dog structure and now it knows the structure that that variable is associating with.
If the structure you're using here is not in the symbol table, this means that no structure exists
with the type you are trying to reference.
So that explains the symbol table and why it's important.
We do need to implement symbol table before we can implement structures.
Right.
So we're going to go ahead and implement the symbol table on the next lecture.
Thanks for watching.