Hello and welcome.
And in this lecture, we're going to start creating a sensitivity, and a sensitivity will essentially
allow us to prioritize operators.
So an expression such as this would result in 2000 multiplied by 30.
Ad 58272 rather than 58272 plus 2000 multiplied by 30.
This is called Bob Mass.
If you are talking about just mathematics, I recommend looking that up if you don't understand it.
Essentially multiplication will always have priority over addition in mathematics.
Right?
Our compiler currently doesn't recognise that our compiler will go from left to right and just parse
into an expression.
We need to reorder the expression so that the operators are the correct way around.
So in this lecture we're going to start writing the code for that.
Before we begin, I just want to show you the C predecessor order so you can see that multiplication
here has a presence of two, has presence of three, so and addition has a presence of four.
This means that multiplication as a higher priority over addition because it has a lower number.
So I recommend looking up a C operator presence manual when following this lecture so we can see that
these ones take the most priority.
These are the second most priority and that's indirection pointer access, you know, not Malta, not
multiplication.
It's actually pointer access.
Yeah.
And here's our addition divide and modulus plus a minus.
And then we have the shifting operators and it goes all the way down and until we reach the commas.
So yes, a comma is an operator in C.
I bet you didn't know that.
Right.
So we can see the associative C here being left to right.
Right to left.
This is how the rules are supposed to be applied, essentially.
So we apply them from the left to the right or the right to the left.
Let's now go back to Visual Studio code and we're going to create a new file called Expression Level
dot C.
So we're going to make the operator reordering and a couple lectures because it is quite a lot to do.
So essentially in this lecture, we're just going to make the table that you see here and we're going
to represent this table as an array.
Okay.
So in our expression with C file, we just create it.
We're going to say hashtag define total operator groups, define max operators in group and that's 12.
Now we're going to make our types for the associative.
So we're going to say a SOS activity left to right, a SOS activity right to left.
So we're now going to create a structure, expression, level up precedence group and that's going to
take a char pointer called operators and and we're going to have max operators in group for its size.
So that's an array of char pointers.
And here we're going to have integer a so sensitivity and this will be equal to either left to right
or right to left.
So this structure that we've created here will essentially represent one of these rows, one two, I
mean, 012, and they'll be put in the array from index zero.
So that's what that's about.
So we now need to create that array.
So I'm just going to put a little common here to tell you how it should be.
So we're going to have a format and it's going to be operator one, operator to operator three and so
on.
And then when we're finished, we just have a null at the end and that signifies we're done.
So what we're going to now do, we're going to make that array struct expression, label up precedence
group.
So we're making an array of the structure.
We just created up precedence total operator groups and we're going to say equals and then we're going
to go operators equals plus plus null.
And just doing that one operators show you how this works.
And then by here we're going to say dot associative equals left to right.
Just like that we can see null isn't defined.
So let's just include at the top of this file, just include compiler.
For now, I'll probably resolve that problem.
There you go.
So this represents one group that has plus plus that's left to right.
Okay.
So if we just go there and C++ there.
Yeah.
So now we need to finish this operator group.
Okay.
So what we're going to do is just before the null, which signifies it ends, we're going to write the
rest of the operators.
So we're going to go minus, minus.
We're going to do those brackets to these brackets.
We're going to do one left bracket there because of the way our paths are works, things are going to
be a little different than represented here.
As I said, when we were doing the lexicon as lecture, where I explained all the different tokens you
remember we had one left token signifies an operator and one right token that looks like this signifies
a symbol that ends the operator, right?
This is why we're doing it like that.
So we're going to do a left to right bracket as well.
We're going to do a dot which will be for like structure access, A dot B equals 50, stuff like that.
Again, we're going to do the structure access for structure pointer access, right?
And then finally we end with our null.
So we've complete the first group, this one.
What I do want to say is we we may be adding separate things in our groups that aren't in here.
So I do recommend watching the video rather than just filling in the list yourself.
Okay.
Because our compiler, the way it compiles things is a little different than GCC, for example.
So our table isn't going to be exactly the same.
Right?
The operator order will be the same, though.
So let's do the next group.
We're going to go operators equals and you all know, see.
So make sure there's a comma there because that's a common mistake.
Even I figured to do that sometimes.
Yeah.
And just by here, we're going to say multiply, divide modulus and null.
We're going to say dot sensitivity equals left to right
next row dot operators equals.
So the next row will be plus minus and null sensitivity equals left to right.
We're going to go to operators equals bit shift left bit shift.
Right now sensitivity equals left to right dot operators equals below, below equals
above above equals.
And then I know again a sensitivity of left to right,
and we're just going to keep going until we're completely done with this.
And again, don't rely on just the table online.
Watch our code because it's not completely the same.
Our table slightly different gives us the same result, but it's not exactly the same as you see online.
So now we're going to go operators equals ampersand.
No.
We're just going to keep going.
So now comes our tanneries,
and this is a right to left.
Okay.
I need to do these ones now.
So essentially doing all the possible operating combinations.
And that will be, again, right to left.
And now, finally, our comma.
And that be left to right, guys.
Okay.
So, yeah, that's right to left.
That one's right to left and the rest are left to right.
Okay.
So essentially when we start making expressions in the future, we'll go through this table.
And if we've incorrectly passed a plus when multiplication was priority, for example, we'll flip the
nodes so that they're in the right order.
Okay, so that's what we're going to be doing in the next couple of lectures.
We're going to be making expression all the work correctly.
So let's just add expression C to the Makefile.
So just by here, we're going to go build impressionable dot.
So that will be for the objects at the top here.
We're going to just copy and paste node.
Oh change that to impressionable.
So it's impressionable .0. C special dot zero.
And then we're just going to go to the terminal.
We're going to make clean, make.
You can see that compiles absolutely fine.
So, yeah, that concludes this lecture.
Thanks for watching and I hope that makes sense about this President's order and why it's important.
Some resources I recommend checking out is body mass because the same rules apply in mathematics, even
outside of programming.
And if you understand body mass, you'll understand why we have to take this operator order into account.
I'm sure you're also surprised to hear that a comma is an operator.
Yes, it is.
So, yeah.
Keep watching the course and we will have operator order.
Correct.
In no time.