Hello and welcome to part five of Implementing the Bodies.
In this lecture we're going to actually call our pass body function.
So we're going to create some functionality which will check to see if we've provided brackets like
this.
And if we have, then it will call our powers body function to parse this into a body.
Okay, so start by going to your test C file and right.
Saying that I've done here have backed paths dot C so just by here we're going to say void, pass symbol.
Okay.
And then by here we're going to say case token type symbol, break pause symbol.
So back at the pass symbol function, we're going to say if token next is symbol, we're just going
to put in the left bracket, then pause body.
And we just want to do a size T here called variable size and we're going to set it to zero.
We're just going to go ampersand, variable size, and we're going to put a history here and we're going
to create a history as well.
Okay.
Now for this test.
We're going to use history.
Flag is global scope.
Now, I'm not promising this stuff won't change.
Right now we're writing this code so I can test and show you the pores body function working.
Because I know we've done a lot of work and we need to implement structures and stuff like that before
we implement these bodies properly.
Like give them an actual use case, right?
So we're writing this simple code here so I can demonstrate the use of parse body and also in C it is
valid to do bodies without statements and structures as well.
So obviously this does need to be taken into account.
So check parse body can see we go parse the scope, new paths of scope finish we can see body single
statement pushes the node body multiple statements pushes the node.
So that's perfect.
So we can expect a body node.
Now the moment the moment that we parsed the symbol, so let's just go struct node body node equals
node pop and that just allows us to examine it.
And we're also going to push that node back to the stack as well.
So we're only popping it off so we can examine its contents to see what happened.
And I've just remembered we've actually already made a pause symbol function.
Let's copy and paste this and we're going to look for pass symbol.
And there we go.
We can see symbols are not yet supported.
So just go over it and just do control V, you know, and paste over our current pass symbol function.
All right.
Because now we are actually starting to define it.
Okay.
So now that we've finished this, let's get open our terminal.
We're going to do make okay.
You can see quite a few warnings, stuff like that.
Don't worry about those warnings right now.
Open up JDB and we're going to go J to B Main and we're going to say break pause symbol.
We're going to go run and we're just going to go next.
Next.
And this is debugger, as you know.
Next, next, next, next.
And then just go print, asterisk, body note and we'll have a look and see that everything's working
fine or not.
So
we're going to actually print the body of the body node.
So what do we see?
Well, we see a size of eight, which is correct.
There's four bytes here.
For bytes here, we see that it's not padded and looks pretty good to me so far.
And the reason it's not padded is because it's aligned already.
We see our largest variable node and we see an array of statements.
So this has actually worked quite well.
So if we just print out the largest variable node, we should see that it's Y and there we go, name
Y.
So there we are.
We successfully implemented the bodies and it tells us exactly how big a body is.
So eight bytes here.
And, you know, we define a body as anything between these curly braces, as I've already said.
So, yeah, there's our size, size of eight.
We can see the array of statements which will have two variable nodes.
So congratulations.
We finished implementing the bodies for now, so we will have to come back to the bodies soon to implement
the upward stack.
And also because we are going to implement functions.
However, pretty much most of the body functionality is now done and I appreciate it's being difficult
because everything depended on everything else.
And obviously if you have had problems at this point or if your result is different from what it's supposed
to be, please message me and I'll help put you back on track.
Thanks for watching this lecture.