Hello and welcome to this lecture.
We are going to create binary numbers, so just go zero be 1110011 in test C and we're going to make
our Lexa understand this just like we did the hexadecimal.
Okay, so just go to Alexa Dot C.
And just by here, we're going to say token token, make special number binary.
And we need to do next see because we want to skip the b OC.
Remember you have something like that, we've already parsed zero into the number.
Now we want to skip the B here so we're left with the binary OC.
So we're just going to go unsigned long number equals zero const char number string equals red number
string.
And then we want to go number equals string tall number string zero two for the binary.
So the base should be two because we're dealing with binary numbers and we're just going to go return
token make number four value number, but read number string also parses 0 to 9, not just binary numbers.
So we need to create another function which will validate that number.
Okay.
So just by here, we're going to say void lacks validate binary string and that's going to take in a
const char and we're going to go size dt len equals string lan string four inch I equals zero I below
len a-plus plus.
So here we're going to say if string I does not equal ASC zero and it does not equal ASCII one, then
compiler error lacks process compiler.
This is not a valid binary number.
And there we go.
Now we ensure that we're only dealing with binary numbers.
We just need a call out function just after we pause the number string.
So we're going to say, let's validate binary string, number, string, and that's that.
It's done.
So let's now scroll down and just by Case X, we're also going to go Case B, which we'll also call
that token make special number.
Now go to the token, make special number.
You can do that on Visual Studio code by holding control and left click.
And we're just going to say else if C is equal to B, token equals token makes special number binary.
Now it's possible that we weren't intending to create some sort of hexadecimal or binary number, so
we need to make a clause for that.
So here what we're going to say is, is if there's no last token or the last token type, it's not a
number
that is zero,
then this can't be a special number.
Right?
So we return token, make identifier or keyword.
So do you get that?
Because someone could just do x 500 rather than zero x 500.
Right.
So this clause here will say, well, wait a minute, no, there was no zero as the last token.
Therefore this isn't a special number and it will then treat it as an identifier or keyword.
Right, which which makes sense because X and B are actually identifiers, right?
They're not keywords or numbers or anything else.
Okay.
So that should be it for special numbers.
Let's just do make clean and make and see if that works.
And we can see that that works fine.
So now we've got hexadecimal and binary numbers.