Welcome back, everybody.
In this lecture we're going to implement keywords.
So just go to Alexa Dot CE and just by here we're going to say bull is keyword and that's going to accept
a course char name, string str and this function is pretty self explanatory.
It's going to return true if the string you provided is a keyword string.
So in it is a keyword.
Sure is a keyword if is a is a keyword and so on.
So we're just going to check for all of those here basically.
So here we're just going to go return s equal str unsigned or s equal str signed
char
init.
And we're just going to go on until we've done all of the possible keywords essentially
and we should probably put that below char so that it increments char short in it makes more sense.
Right.
Float
double
and we missed long right here.
So let's just do that long
void
struct
reunion.
So basically implementing everything that was on the lexical analysis video when I showed you all the
keywords and all that we're implementing all of that basically ignore type check and we should only
have one under scroll in the middle there.
So that's not strictly a C keyword, that's our own custom keyword there for ignoring type checking
return
include
size of
if
else
while.
Four
two.
And we're just going to go on and on until this is completely done.
And finally restrict arc so that all the keywords that matter in our compiler, there may be one or
two others that we're not implementing, but that looks like the whole lot.
I suppose we're missing things like attribute, which can be used to pass rules to structures and so
on and functions.
But we won't worry about attribute right now.
So just scroll down to our make identifier or keyword function that we made in the last lecture when
we implemented identifiers.
And you'll see here where it says, check if this is a keyword.
Well, we're going to do just that.
We're going to say if it's keyword, buffer, pointer, buffer, then return token, create
struct token type equals key equals token type keyword task file equals buffer pointer buffer.
So you can see and just like that, we have keywords, right?
So that's how it works.
So it comes in here, it parses the string.
If it's a known keyword returned in is keyword here, then we'll create a keyword token.
Otherwise we'll create an identifier token.
So yeah, perfect.
Let's try that out.
So we're going to say make clean, make.
So just go to test start, see.
And we're going to go in it long domain and it says everything compile fine well everything compile
file.
I really have to fix that spelling error.
Right.
So yeah, that is that's perfectly fine.
It works.
We're now parsing identifies and keywords.