Hello and welcome everybody.
And in this lecture we're going to implement LS and LCF statements.
In the last lecture we implemented EF statements.
So let's head to compile our H.
We're just going to scroll up here and just scroll up to your statement just by here we're going to
say LS statement OC We don't need an LS if statement because all in ls f is is an F statement.
Okay.
So in the case of an l f, the structure next year will point to the next f statement.
Otherwise it will point to an l statement or no OC.
So what else statements have?
They only have bodies.
They don't have anything else.
And the reason they only have bodies is because their L statements.
L statements don't take any arguments.
So that is all you need to do for the compiled file.
Let's head over to past that C and we're just going to go to parse F and we're going to actually create
the functionality to parse the L statements and the CIF statements.
So now we're going to say struck node pause else or else f and you know, that function is pretty self-explanatory,
right?
It's going to parse an L statement or an L CIF, depending what it sees.
Now, we're just going to say struck no, node equals no and we're just going to return the node down
here.
Copy and paste the prototype for positive statement above here because we're going to call that at some
point.
So now we're going to say F token.
Next is keyword.
And we haven't yet implemented that yet.
That's okay.
And we're looking for an else keyword.
Okay.
So if there's an LS keyword, then we know we have an else, we have an LS or an LS if we don't know
which one, but it's one of them.
So we're going to pop off the LS statement that we just checked pop off else because there's nothing
we can use.
We can't really use that.
It's not really informative to us once we know what it is, so we just discard it.
No problem.
And now we're going to say if token next is keyword F, then this is an L CIF okay, this is an else
f, not an else.
So in the scenario where it's an LC if not an LS, we go node equals positive statement history and
then we return return the note and we actually want a history down this as well, guys.
So history zero.
There you go.
And positive statement is a returns a void.
So it should actually just be positive statement node equals no pop.
That's what we should do.
Like that positive statement node equals node.
Pop, return node.
Problem solved.
Now, if it's an LS statement, then that code won't run.
So it's an L statement.
And what do we do if it's an L statement?
We say size t size equals zero.
Parse body ampersand var size history down history zero.
Struck note body note equals no pop.
And then we're going to say make else note body note.
And we're going to say no equals node pop.
Just like that.
Nice and simple.
So we need to create some functions now.
We need to create the is keyword and the make else node.
So just search for token.
Next is operator.
And just in the here we're going to say static ball.
Token next.
Is keyword conscious keyword struct token token equals token peak.
Next return token is keyword.
And we're going to say token keyword.
So that's that one done.
Now head over to node dot C and we're going to say void make else node struck.
No body node.
We're going to say no create ampersand struck node dot type equals node type statement.
Else dot statement dot ll statement dot body node equals body node.
Nice and simple.
Copy and paste that.
And we're going to put it in compiler H and under make if node OC head back to parse the dot C and we're
going to go back to our parse else or else F and we're going to put this in its own function.
So we're going to say node equals parse else and we're going to pass in the history there and we're
just going to say struck node pause.
Else struct history history and this history down we're going to get rid of it and we're just going
to put history here.
And just by here we're going to paste that in history down history zero.
So then we need to obviously return the node or we can just go return node pop.
That would be absolutely fine.
Right click from a document.
So that's the code guys that parses the else.
This parses the or elseif and now the final thing to do and I'll make if node in our next node we need
to say pause else or else if history nice and simple and we're going to go make clean make.
And we're going to just test that.
So we're going to go to test let's see.
We're going to say like f two and it x x equals 40 else and it dx equals 44 or whatever.
I don't know.
Let's try that out.
We're going to go main everything compile fine.
So that's perfect, guys.
We've now implemented LS and LC for our F statement.
Parsing is done.
Congratulations.