Hello and welcome.
And in this lecture we're going to implement identifiers.
So what are identifiers?
Identifiers are any words number combination that are not keywords and the numbers must come after the
letters.
So this is an identifier.
This is an identifier.
Okay.
So all of these are identifiers.
This is a keyword.
Okay.
So we're going to be implementing identifiers in this lecture.
And because we haven't implemented keywords yet, keywords will also be seen as identifiers.
But we'll change that when we go to implement the actual keywords later on in the course.
So just head over to Lexi and we're going to start creating identifiers.
Okay?
So what we're going to do is just appear, we're going to say static struct, token token, make, identifier
or keyword, and we're not making keywords in this lecture, but we will work on this function later
on when we actually implement the keywords, which is why we're naming it make identifier or keyword.
So when I was just going to go stroke buffer buffer equals buffer create, we're going to peak to the
next char and we're just going to say, let's get C, F, buffer C and the expression will be C above
or equal lowercase A and C below or equal lowercase C or C above or equal uppercase A and C below equal
uppercase C or C above or equal zero and C below equal
nine and finally identifies can have a under scroll so all C equals equals underscore.
Now we don't have to worry about them putting numbers before the letters because to even get to this
function we would have had to detect some sort of ASCII alpha character and we don't actually need the
peak C here, so we can just set that to zero because if you look in like get c if.
We do the peak.
See here.
Nice.
So now we just write the null Terminator.
Now here we check for the key word check.
If this is a key word, we're not going to do that in this lecture.
And if it's not a key word, we're just going to return token create ampersand struct token type equals
token type identifier as val equals buffer pointer buffer just like that.
So that creates our identifier token.
Perfect.
So we're just going to create a new function called read special token.
And special tokens will essentially be situations where we don't really know what something is until
we look further ahead.
Okay.
In our case, is is it an identifier or a key word?
Right.
So just in here, we're going to say char equals pixie equals pixie and we're just going to say F is
alpha and we haven't created that function yet.
We will or C is equal to an underscore, then return token, make identifier or keyword.
Otherwise we're just going to return null.
So that will basically read the special token.
And if it can't find one, it will return null.
Right.
So is alpha can be found in C type H.
So just scroll up and we're going to say include C type H.
Yeah, that's fine.
So we're just going to scroll back down and and read next token.
And just in the default, we're going to say token equals read special token.
And if the token is null, then there will be a compile error.
Awesome.
So that should be it.
We should now have identify as less do and make clean and see, make, clean, make.
And then we're going to go to test, start, see.
And we're just going to write some words.
Everything compile.
Fine.
Put a few numbers there.
Everything compile, fine.
So we've now implemented identifiers.