Okay, everyone, in this lecture, we're going to try and break our functionality.
You know, we want to try and make something break so we can fix it because we'd rather get all the
mini bugs if there are any out of the way now.
So let's go to the semicolon and see what happens, right?
So we're gonna go to the semicolon, we're going to say in it a and then we're going to say make just
to build it.
We're going to go main and look at that expecting symbol semicolon.
So you can see it's called it's called the issue.
Let's put another semicolon there.
Run it again.
Everything's fine.
Let's get rid of this.
What happens if we have no tokens and there's a semicolon?
Let's see what happens.
We're going to run main.
We can see that everything compile.
Fine.
That's because I forgot to remove the semicolon.
Get rid of the semicolon, guys, run mine again.
Oh, okay.
We have a segmentation fault.
Let's figure out why.
So we're going to go JDB Main, we're going to type run and then we're going to do backtrace so we can
see there's a bug on line 984 of the paths that C file.
So let's go to parse dot C, we're going to go control g984 and we can see in the past struct no new
scope function there's a bug on line 984 by here.
So what is the issue?
Well, we're checking to see if there's an X token and then we're immediately checking the type, but
we're not checking to see if the next token is null first.
Right.
That is the problem.
Okay.
So we're going to get around this.
We're going to go to token dot C and we're just going to say pull token is identifier and we're going
to pass in the actual token, we're going to go return token and token type equals token type identifier.
And this is in the token dot C file.
Okay, guys, we're going to copy and paste the prototype to compile dot hatch in token is keyword just
under here.
Okay.
So, you know, to export the prototype to us.
So now we have a nice clean function we can call which will check to see if the token is not null first
and then it will check to see if it's an identifier.
So we go back to parse a dot C
and now we get rid of token peak next type and we just did token as identifier and then we went token
peak next.
Now if token peak next returns null, it doesn't matter because token is identifiable, check for it.
So the bug was very simple guys.
We basically went token peek next type equals equals.
Now obviously token peak next returned null in this case because there was no more tokens.
Hence we accessed a null variable pointer basically.
So let's try that again.
Now we're going to go make clean make and then we're going to run main.
We can still see a segmentation fault.
Let's see what's wrong.
We're going to say run backtrace and we see on token next line 109 that it fails to get the next position,
which makes sense because there is no next position.
So let's go to 109 and we see next token here.
Okay, we now want to change this.
So we say F next token, then set the current position and that will ensure we're checking for that
as well.
So if we now do a make clean again and make.
We ran mane.
Perfect.
Now we can see the bugs are gone.
And that's all working as expected, which is great.
So yeah.
Simply put, the problem with that token next was, is when we go to set the current process position
to the next token position.
Obviously same problem happened.
There was no next token and therefore we basically accessed position on next token, even though next
token was null.
So by checking if it's there, we get rid of those no pointer problems.
Thanks very much for watching.
And yeah, that is now bug free.