Hello and welcome, everybody.
There's some more reordering code we need to write because we haven't taken into account for reordering
of assignments and array brackets and stuff like that.
So what are we going to say?
We're going to say F is array node node expression to the left.
And we need to implement this function, by the way.
And then we're going to say and is node assignment and don't we will implement these functions.
Node expression, right.
We're just going to put in another parentheses around there and we're going to say all node is expression.
Again, we haven't made any of these functions.
We'll do it.
Node expression, dot.
Right.
We're going to look for a parenthesis node there or node is expression node expression, right array
bracket.
And so this should be left, not the right left.
And we're going to put another bracket there, another bracket there.
And just by here, we're going to say and node is expression, node expression dot.
Right, this one is dot.
Right.
Comma.
So I appreciate that is a mouthful.
We'll probably put it into another function at some point just so it's cleaner and I think we need to
put another bracket there as well, guys at the end.
So if the left operator, the expression is an array node and the right operand of an expression is
an assignment, then we kind of need to move the nodes around and the same situation for these for this
expression as well.
So you'll see more about this when we actually start writing the code.
So we're going to call a function here, parse a node, move right, left to left, and ask and expect
the node that we have here.
Okay, so let's just press hold control and left click this pause node shift children left and we're
going to right under here that same function.
Okay.
So the first thing we're going to say is make expression.
Node node expression left.
Node expression right.
Dot expression left
like that.
And the operator will be the node expression operator.
So what we're doing here is we're making a new expression node that uses the left node here in the node
we provided, and that becomes the left node.
So it doesn't really change.
But then we go into the right node and we grab out the left node, and then that becomes the right node
of this expression node.
So we're going to say struck node, completed node
equals no pup.
So we still need to deal with the right node.
So what we're going to do, we're going to get the new operator.
So we're going to say node expression.
Dot right.
Dot expression.
Okay.
So now this this existing node, the one that was provided to us, we're going to change some parameters.
So the left now becomes the completed node and the right node becomes the node.
Expression.
So right.
Expression.
Right.
Finally we say node expression up equals new op.
Okay, so this is the procedure for moving for this operation.
Okay.
So let's now head back to the function where we call this OC and we're going to implement is array node
and is node assignment.
So firstly know that is array node is basically the exact same thing as this OC.
So for that reason we will also change that in a moment.
Okay.
So let's just head over to Nodes C and we're just going to essentially scroll to the bottom.
We're going to say ball is array node that's going to accept the node.
And just above here we're going to say pull node is expression.
I can't remember if we've done that already.
Let's check.
No, we haven't.
So that's fine.
So all note is expression, and we're going to accept a note and we're going to say Return no type equals,
no type expression and SX equals note expression op.
And we're going to put up in here and then we're going to have Concha OP.
We're now going to say return node is expression.
When a pass in the node, we're going to pass in those two array brackets and now we're going to do
ball is node assignment going accept a node.
And we're basically going to say if no type does not equal node type expression table return false otherwise
return s equal node expression op is equal to equals or.
Is equal to plus equals or c equal to minus equals or is equal to divide equals or is equal to multiply
equals or is equal to.
Yeah.
In that set we can also add the bitwise operators here, but we're not going to worry about that for
now.
Such as or equals.
And the reason why not?
Such as?
Shift.
Shift equals.
And the reason we're not going to do that now is because I want us to get the product working and then
we'll come back and improve things and make things a bit cleaner because this might be better in some
sort of array, I think.
Okay, so what we're going to do, we're going to copy and paste.
All of these into compiler hedge
and
that should be at.
Done.
So now we're going to do a make clean and to make.
You can see everything compiles fine.
Perfect.
So, guys, I just want you to go to test C and you can see I've written this little example program.
I've written this example program just to demonstrate when this clause is called line three, five,
four.
So I'm going to explain why we have to do this, what we've done here.
So, right, write some code.
This like this.
So you've got a structure function.
And we just call function test and just pass.
Yeah.
Pass more arguments that exist.
It's okay.
We haven't created a validator yet.
And once you've done that, we're just going to do a make.
And we're going to JDB Main.
And we're just going to do a break on the line just before we call pause and move right, left to to
to right type run and just print the node so we can see that this node is an expression node.
So let's do node expression so we can see if I get up.
G So we can make this a little more graphical.
We can see that the root node of the expression.
Is ee
och and the operator is a dot.
Let's see what the left node is.
So we note.
Expression left to type so we can see we have another expression on the left node and on the right nodes
we have another expression.
So let's look in to the other expression and we can see we have our a bracket.
So.
On our left note, we have an array bracket, so we're going to go to question left.
Dark splash dot expression left type.
We can see our type of three there.
Yeah.
So I think what is the type of three again.
Let's have a look.
So we've got no type 0123 identifier.
So we're just going to go as file and we can see box.
So there's our box and what is our right value for that?
So let's have a look of what the right value is.
And I'm breaking down the problem for you so you can see why we've done this code, because this code
is quite hard to explain.
So it's best I break it down in the debugger.
So you can see why we've written this code and we will tell you this code up a bit as well, because
it could be a bit cleaner.
So we can see that's a type of 26.
So let's have a look.
We got a bracket, okay, no type of bracket.
So let's open up the bracket and see what the inner is.
And I guarantee you it's the number.
At a sec.
Yes.
It's the number.
So.
Number two, which is no type number.
So our left operand looks like this E box and we have that and then we have the zero.
Okay.
So there's our expression,
there's our left expression, which is box bracket zero dot, and then we have a right expression.
So let's see what the right expression is.
So we're going to have to go all the way back, no type expression, right?
And we're just going to go like that and we see the type of zero.
So there's also an expression involved.
So we're going to look at that.
And there we go.
We see a calmer expression here.
So for our second expression, we have a comma for the operator, and the left node is
a number node.
So let's just go left.
L l numb now and identify a node.
Sorry, left se file and we see name.
Okay.
So name is on our left node.
Now what is the actual right node of that.
So we're going to look at the right node.
That's that's the number and we have our 1000
OC so we go to test and see.
We can see our expression here is book's zero dot name, comma 1000.
So can you see what the problem is?
Our plaza has incorrectly parsed this this line.
It sees it as this box zero.
OC dot name 1000.
That's how it's interpreted it.
Which is obviously very bad.
Very, very bad.
That's how it's interpreted it.
So obviously that doesn't make any sense, does it?
So this is why we have this function.
So if we now go into this function, so we're going to break, pause the node, move right to left break,
pause the node, move right, left to left.
Press C and we're going to go next.
Next.
Nex nex next, nex next.
Now we're going to go print across node again so we can see that it's still an expression node.
So now look at look at the difference.
So we're going to go through this process again.
And this was the best way for me to explain that code to you, because it is a bit confusing, right,
of why we're doing that, which is why I want to break it down.
So now if you look here, you can see the difference, right?
Our root expression node has a comma, no longer a dot.
Okay, so let's create a new expression, root expression, and we're just going to put a comma there
because that's all we know so far, comma, left and right, because we don't know the left and right
yet.
So now we're going to say expression, dot left type.
So that's another expression, right?
So now we're going to look into there.
So what does the left have?
It has another expression.
It has another left.
It has a dot and another right.
So let's resolve the root left expression first.
So we're going to say node expression, dot left expression, dot left type.
We can see we have another expression.
So we're going to see expression.
So we can see that the left.
Is another expression with that being the operator, and we have a left and right, so let's see what
the left is.
So the left is a type of three.
So we have.
A identifier.
So left is box.
Let's look and write.
And this is why I'm showing you this way, because it's hard to explain that code, right?
So the right type is 26, which is bracket.
So we're going to say bracket inner type and we have a number which is zero.
And now we're going to look at the right note.
So we're going to do expression dot right type, which is three, which means it's a number.
No.
A identify.
Sorry.
So we can see that's name.
So already you can see what's happened.
We haven't even passed the right bracket.
Yeah, we're about to do that.
You can already see what's happened is this name has been merged into a new expression so that it can
maintains itself on the left expression of the root expression.
So now we're going to look at the actual right of the root, which is a number of a thousand.
And there we go.
The conflict is resolved.
So this was the one that was incorrect because it produces an output that looks like this.
The reason I put the brackets is technically not brackets.
It technically looks like that.
Right.
But the problem is they are separate expressions.
So it sort of looks like that.
Okay, this is how the the one that's wrong looks so we can see box zero and then we have another expression
named comma 1000 and this is wrong.
And now our new expression, it looks like this box zero dot name, comma, 1000.
So this one is correct.
So that is what we we are doing with that code that I wrote here, that we wrote here,
and that is why we do it.
And this code could be cleaned up a little bit, so we will actually clean that up now, I think.
Okay.
So we're going to we're going to just clean this up a little bit.
What is the first thing I can notice?
This seems to be illegitimate.
I don't think we need it because we have it here.
So I think what it really should be, this should become an or this should be deleted.
I believe that's correct.
The correct thing to do so we say is array node or is node assignment or node is expression and node
expression.
Right.
Okay, that should work.
Let's do a make clean.
It's still a bit messy.
Let's do a make again.
I remain and we can see everything's fine.
So that's the version we have now.
I probably will have a lecture in the future where we just come back, clean things up a little bit.
I could probably be best in its own function, I think.
But yeah, this is all a learning process for your students, so we're not going to go into too much
optimization at the moment.
That will come when there is more of an understanding of the project further to the end of the course.
Thanks for watching.