Hello and welcome, everybody.
In this lecture we're going to start creating our parser.
So the first thing I want you to do is I want you to go to a compiler page and we're just going to scroll
up to compile process and under token VEC we're going to create a new vector and this will be called
node VEC.
And we're going to create another one called Node Tree Vec.
So these are vectors of nodes and the Noveck will be used to kind of push and pop nodes while we're
doing the parsing process, whereas the node tree VEC will be the actual root of the tree.
So that's what these two vectors will be used for.
So we now need to initialize them.
So just go to C process, start C and we're just going to go process no equals vector create and we're
going to have to include vector up here as well guys
sizeof struct node pointer.
So every node will be a pointer.
Unlike with the tokens where we're pushing it by value, we're not going to do that here.
It's going to be by pointer and we're going to do the same process.
No tree vec equals vector create size of struc.
No pointer.
Okay.
So both of those statements create vectors of nodes, essentially.
So now we're ready to create our parser.
So let's just create a parsed C file and we're going to include compiler dot and we're going to include
the vector dot as well, helpers, forward slash vector.
So our pass function will just be called parse.
So just go in at parse and that's going to accept a compile process and it's going to return parse all.
Okay.
And we're going to define this now, so just go to configure Hage.
And look for Node.
Yep.
And just above.
Here.
We're going to define those enumerations.
So we're going to go in
pause, all OC pause, general error.
Okay, so they're the two different return codes that our paths can return.
So just go to parse that.
See, we can see that now resolves correctly.
OC So just up here we're going to say struct compile process, current process and that's going to be
static and we're going to say current process equals process.
This allows us to not have to pass the compile process to any functions during parsing because the current
process will always be set and that also needs to be a pointer like that.
And what we're now going to do is we're going to say vector set, peak pointer process token VEC and
we're going to set the P pointer to zero and we're just going to create a new function called Parse.
Next, we're just going to return zero for now.
And in here we're going to say while parse next equals zero nodes equals no peak vector push process
node, tree vector and we're going to do ampersand node there.
And just by here we're going to say struck node node equals null.
So now let's just add the parser C file to the Makefile.
So just by here we're going to copy and paste and just to parse the dato parsed C and we're also going
to add it at the top here as well.
Top forward slash.
Build the data just like that.
Perfect.
Go to Pastor See and we're just going to come on this because we haven't created the function yet for
no peak.
We will create it soon in the next lecture.
And what we're now going to do is we're going to go to compiler dot C and just for our compile file,
we're going to perform parsing.
So just by here, we're going to say if parse and we need to actually put that in the header file guys
as well.
So just go to parse out, see copy and paste the prototype of Parse and we're just going to put it in
compiler dot hedge.
Okay.
Just under Lex.
I'll be fine like that.
Okay.
So now it can see it back to compiler.
C so we're going to go parse process does not equal parse all okay then return compiler failed with
errors.
Okay.
Nice.
So that now links our parser to the actual compilation process.
So you can see our parser doesn't really do much so far.
What we will do when we implement Parse next is it will go through all the tokens and create nodes.
And then finally when parse next no longer returns zero, the parsing is done.
Okay, but that is a nice little skeleton for us to work with as we go through this section.
So I now want us to do make, clean, make and we can see that compiles perfectly.
So that concludes this lecture.
In the next lecture we will work on creating node functions.
So we'll create like things like no peak node pop stuff like that.
Okay.
Thanks for watching.