Hello and welcome.
And in this lecture we're going to implement casts.
So the first thing I want you to do is search for parse expression.
And just above here, we're going to say void parse for cast.
That's going to accept a history.
And you know what?
We actually don't need a history for this one, guys.
I don't think so.
We're going to say struct data type, de type.
And this is the cast data type, right?
All right.
And we're going to parse the data type.
And at this point in time that this function is called the left bracket of the cast is already parse.
So, for example, char is seen as
char once this function is entered.
So this would have already been parsed at this point.
So we can call, parse data, type and be left with this ending parentheses bracket.
So then we do expect SYM to get rid of this ending bracket here, which will leave us with the parsed
data type, that being the cast.
So now after a char, after a cast is always some kind of expression, right?
So we need to deal with that.
So we're going to say parse expression of all history begin and we're going to put zero for the flags
and now we're going to pop off the operand node, which is the one we just paused with.
Parse expression double.
And then we're going to say, make cache node, ampersand, DX type operand node.
Okay.
So now we're going to head to compile H to make the actual cast structure.
So we're going to search for our statement.
We're going to scroll all the way down.
And just on an old label, we're going to say struck caste,
caste.
And that's going to take a data type and a pointer to the upper end node and we can just call that upper
end.
So if someone was to do CHA or let's say in 56, then you can see that the data type here will be an
integer and the upper arm will point to the 56 number.
So now back to positive dot C and we can see we need to make the cast node.
So go to Node C and further down here we're going to say void, make cast node struct, data type and
this is a pointer struck node operand node and we're just going to say no, create ampersand struct
node type equals node type cast dot cast d type equals asterisk type because we want to copy it.
We want to copy it into there.
Right, because that's not a pointer.
The thing provided is a pointer.
We want to copy it.
So we use an asterisk there and then we're going to say dot cast, dot operand equals operand node.
Okay.
So we're now going to copy and paste this into the header file.
Just like that, and then that's resolved correctly.
And now we're going to go to pause for parenthesis function.
And just by here we're going to say if token peak next
type equals keyword, token type keyword.
Then pause for cast and then we're going to return.
So this makes sense because if someone did this and we see the char there, then we know that there's
a cast.
If they did if they did that and put a struct there and we know there's a structure.
So I know what you're probably thinking.
What about things like typedef structs?
Well, since the preprocessor will run before anything else, when we get to that, we will have all
of that resolved.
So even if you had to type def, it would still be seen as like struct ABC or something.
So you don't need to worry about that.
Okay.
So we're going to try to clean that now and build it.
And we have a couple of warnings.
So let's see what we got.
Implicit declaration of powers for cast and declaration of past data type.
So that's no problem.
We're going to fix that now.
So we're going to search for parsed data type.
And we can see that that's that we're going to copy and paste the prototype here.
We're going to put it at the top.
Of the of the source file just by there will be fine and we're also going to write void parts for cast
because we also want to forward declare that one.
So once you've done both of that, we're going to do a make again.
You can see the warnings are gone now.
Okay, so now let's do a main.
You can see everything is fine.
We're going to go to test C and we're going to say in it 30.
We're just going to see if that works.
We're going to go main and we can see everything is fine.
So we now have casting paths successfully.
Congratulations.