Hello and welcome, guys.
And in this lecture we are going to create quotes.
So what are quotes?
Well, you all know what that is, right?
Chelsea equals, quote, Skyfall.
So we're going to actually make these quotes here.
Okay.
That's what we're going to do today.
So just head to Alexa Dot C and just by here, we're going to say struck token, token make quotes and
we're just going to say char C equals next C.
If C is equal to the to the two back slashes, then we have an escape such as backslash n yeah, but
we ain't going to deal with that here just yet.
So we now need to basically say if next C does not equal the quote, then compiler error lacks process
compiler.
You opened a quote but did not close it with a quote character.
And then we're just going to go return token create struct token type equals token type number
and then we're going to say dot C, val equals C.
So yeah, technically characters, even if they're in quotes, their numbers write their numbers from
0 to 2, five, five, so they still count as numbers and they should create number tokens.
So that is our function for creating quotes.
We haven't implemented this bit yet, but we will implement that.
Just scroll down here now and we're going to say case quote Token equals token, make quote and we're
just going to break.
So back to our token a quote and we're just going to go C equals next C.
So that will basically take the the end character, right?
If they did a backslash.
N So we've already popped off the backslash here and now we're on the N character.
Okay.
So this, this C will now equal the N character, right?
Or whatever sort of escape they did.
They could have done a tab or anything, right?
So now we're going to say C equals Lex get escaped char and we're just going to pass in C by that and
we're going to have to create this function as well, guys.
Okay.
So just by here, we're going to create that function now.
So let's get escape cha cha.
See, we're going to say cha co equals zero return co cha out.
Basically, guys, we're going to say switch c case and break.
And in that case the C out will be backslash n new line case backslash and that will be backslash case
T and that will be tab
case quote
and that will be quotes just like that.
So that kind of converts the character they provided here into the actual binary equivalent.
Because remember, when they pass as the character here, all we're seeing is like an N and or something,
right?
Or a T and if we pass that straight to like a input stream or an output stream, it's just going to
output a t, it's not going to put a tab, right?
So we need to actually convert that T into the escaped equivalent OC.
So that's why we're doing that.
So before I forget, we actually haven't popped off the quote character that started this thing yet.
So all we're going to do is we're going to say a set next char.
We're just going to put a quote and we're going to create that function and it's basically going to
go to the next char and check if it's equal to what we put here.
Right?
So essentially what we're going to do, we're going to pop off the quote here.
We're going to check that it's actually a quote and then comes the character.
So that's the correct way to do that.
So just scroll up.
And just by here, under next sea or in the sea, I should say we're going to say static cha assert.
Next cha cha sea.
And then we're going to say cha next sea equals.
Next sea asserts that the sea is equal to the next sea.
And then we're just going to return next sea, just like that.
So, yeah, let's now go back to our token and make quote.
We can see everything is now correct and we're going to test this.
So just go make clean, make.
And we're just going to go main everything compile fine.
And you can see I added these these quotes into the test at sea file before we start this lecture and
we can see that that works absolutely fine.
So if we do a backslash, send there quote backslash m quote, we try that again.
We can see everything compiled fine.
So perfect, everything's working.
So we've now implemented quotes.