Hello and welcome, everybody.
In the last lecture we started implementing functions.
In this lecture we're going to implement function arguments.
This is an exciting lecture because once we finished implementing the function arguments, we've basically
finished implementing the functions for the most part, apart from some minor changes with the code
generator later on in the course.
So now let's start this lecture.
So we're going to create a new function, struct vector, parse, function arguments, struct history,
history.
So obviously what we're going to do here is we're going to parse the function arguments and return the
argument vector.
So function arguments will always have a new scope.
So we're going to say parse a new scope or parse the scope new.
I mean, now we're going to create a arguments vector
and that's going to hold structure of no pointers.
So we're going to say, well, token next is not symbol right bracket.
Then there's obviously more arguments to come because at this point in time, we're basically seeing
something like this, right?
Or something like that.
Yeah.
So the pause function arguments will basically see this.
So it will check to see that there's no right bracket.
And if there's no right bracket, it'll keep parsing them.
Does that make sense?
Okay.
So we're now going to say F token next is operator and we're going to look for a dot.
I'll explain more about that in a moment.
And if there is a dot, we're going to say token three, dots three and we're just going to go void
token red dots, size T amount, basically going to say for any I equals zero.
We could say size I guess I below amount A-plus plus and we're just going to say expect up I'm just
going to put a dot in there so essentially you can have dot, dot, dot the end of any function to basically
say that this is a VA list.
And I expect you to know what a VA list is for this course.
So please read up on it.
Basically allows us to have infinite arguments.
It's a little like how printf works.
That's why we can always add more arguments, right?
Because it uses these three dots which signifies a VA list as required.
So if we see one dot, we read three hope.
That makes sense.
If we do encounter this dot, we know there's no more arguments because dot, dot, dot is the final
argument.
You can't have more arguments after that.
So because of that, like you can't do something like this, for example, you can't do that.
The dot, dot, dot can only be at the end.
So because of that reason, we are done parsing when we find those dot, dot, dot.
So we do pause the scope finish and we just return our arguments factor.
Okay, so by here we're going to say pause variable full.
We haven't created parse variable full yet, so let's just create pause, variable false.
So we're going to say void, pause, variable, full struct, history, history
and basically our pause, variable function, it expects a type, a name, stuff that we don't have.
Right?
So pause here before will pause those and then cause and then call pause variable.
So we're going to say struct data type, dx type.
There'll be a stack variable parse data type, ampersand d type struct token name token equals null
if token peak nex type is equal to token type identifier, then name token equals token next.
And then we just say ampersand type.
We say name token and we say history.
Okay.
So now down on parse variable for where we call that, we're going to say history down history history
flags odd with history flag is output stack because obviously all variables that are function arguments
will have an upward stack because we need to access up the stack to access them.
AB Plus a.
Plus 12.
Stuff like that.
So I did go over the upward stack briefly a couple lectures ago when we actually implemented this pit
mask.
So if you if you are a bit confused, just check back when we implemented the upward stack and you'll,
you'll understand a bit more about that.
Basically, when access and function arguments we go up the stack when accessing local function variables,
we go down the stack.
So we're going to pop off the variable node, let's call it an argument node
and we're going to push it to our arguments vector.
So now we're going to say if the next token
is not a comma operator, then there's potentially more variables to parse.
Because if you imagine we had something like this, we've just come in here, we've parsed in it x,
we have a comma, right?
So because we have a comma, we loop back around and then we would then pause in it.
B And then eventually we find this right bracket, which signifies what I'm parsing the function arguments.
So if there isn't a comma, then we must be done because there can't be any more arguments.
Right?
So we break now.
If we reach line one, one, three, three, then that obviously means there was a comma.
So we need to pop it off.
So we just do token next, pop off the comma.
I can't I can't let you know enough to use comments as it will make your life so much easier.
I mean, if you don't comment that you might get confused later on, right?
So pop off the comma token.
Next done.
Okay.
So finally we're going to say pause the scope finish and then we're going to return the arguments factor.
So that should be it.
So, yeah, we go through here all the function arguments, we parse the variables from them, push
to the arguments factor.
If there's no comma, we're obviously done parsing arguments, we break.
Otherwise there is a comma.
We pop it off and we loop back around until we find the right bracket.
So that's awesome.
Well done.
This takes into account all possible scenarios, including whether or not there's only one function
argument.
So there's only one function argument.
Then it will be caught.
It will be caught here because we'll break because the next the next token will be this right bracket.
Okay, guys.
So now let's just go to parse function again and note.
It's the warning we put here.
It no longer has to be a warning to arguments.
Vector equals parse function arguments and it's going to ask for history just to history begin to pass
in a zero.
And there we go.
That should be it so as to make and make clean.
You can see conflicting types of paths, arguments is to see where that conflict and type is.
Hold on.
Okay.
So there's implicit declaration because this function is further below.
This function.
That's okay.
So just copy and paste the prototype, parse function arguments and put it at the very top by there.
And we're going to do a make clean make.
We can see everything builds absolutely fine.
We do see a not yet implemented.
That's okay.
So then guys, why do we see a not yet implemented?
Because we haven't yet finished implementing upward stacks.
So that's no problem.
When we implement the upward stacks, that will work without any issues at all.
Okay.