Hello and welcome.
And in this lecture we're going to implement tanneries.
So tanneries are kind of like where you do 50 question mark 30 colon 20.
So if this is true, value is 30, otherwise it's 20.
So we're going to implement that now.
So if this was zero, it would pick 20.
If this was above zero, it would pick 30.
If you don't know what tanneries are, have a good read about them because that's what we're implementing
in the plaza to date.
Okay.
So let's scroll down to var list in the structure node.
And just above here, we're going to say struct node tannery and that's going to be called tannery.
And this can accept a node called true node and the node called false node.
Okay.
So how this is going to work is the actual expression, the 50, and our example will be its own expression
node.
And then everything after the question mark will be the node ternary.
So in this example, the true node is number 20 and the false node would be number ten.
OC Okay, so once you've written that, go back to positive C and let's just search for pass keyword.
And just above here, we're going to say void pause for tannery struct history, history.
And the first thing we're going to do, we're going to pop off the condition node because remember,
it's already been parsed at this point in time.
And then obviously we expect the operator question mark.
Now we're going to say parse expression, double root and we're going to say history down.
History, history, flag parentheses is not a function call and we're going to create that now.
So just copy and paste that and we're going to scroll up just down here.
We're going to paste that in in our history flags to shift the one to the left.
Now we're going to say struck node.
True result node equals node pop.
And obviously we now need to expect the symbol colon because we're going to parse the false and we're
just going to copy and paste this line, be the same thing, and then we're going to pop off the false
node
and then we're going to call make ternary node, which we haven't created yet and we're going to pass
in the true result node and the false result node.
Now we pop it off.
Finally, we make an expression node that contains the condition node for the left, the ternary node
for the right, and the operator question mark, which signifies a tannery.
Okay, so now we're going to go to nodes, see, we're going to say void, make ternary node struck,
node true node struck node false node.
And we're going to say no, create ampersand struck node type equals node type ternary dot ternary dot
true node equals true node ternary dot false node equals false node.
So that's it for that one.
Let's copy and paste this into compile that h
just like that.
So now we're going to search for parse expression which is here and we're just going to say elseif s
equal token peak next SX file is equal to a question mark.
And if that's the case, we're going to say pause for ternary and we're going to pass in that history.
So let's copy and paste this at the top.
Here so the prototype can be found.
A search for paths for ternary.
And there we go.
That looks okay.
So now we're really going to try this.
So we're going to do a make clean and make way to go to test see.
And we're just going to get rid of this.
It's going to be messy.
We're going to say X equals 50 question mark, 20, colon ten.
And then we're going to do main and we can see everything works fine.
So we now have ten inches.
Congratulations.