Welcome back, everybody.
In this lecture, we're going to implement symbols.
So just go to compile a sketch.
We're going to scroll up to the operate case, excluding division, and we're going to make a symbol
case.
So we're going to go to find symbol case.
We're just going to go.
Case left bracket.
Case right bracket.
Case colon.
Case semicolon,
case hash tag case backslash, case right bracket, which will close expressions.
And don't forget your colon.
Case.
Right array bracket which will close the array expressions.
And just go to that final colon there and that new line.
Okay, nice.
So these are all the symbols we'll tokenize.
Implementing the symbols in our lexa is actually going to be very easy.
So this is going to be a quick lecture.
So let's go to Lexa C and just go to Lex new expression and just under there we're going to make something
that closes the expression.
So let's finish expression and we're just going to say Lex process current expression, count minus,
minus.
And the reason we're doing this here is because the right bracket here is a symbol, right?
So we're actually going to be using this Lex finish expression in this lecture when we finish implementing
the symbols.
So if the current expression count is below zero, then this means they had a right bracket without
a left one, which means they basically closed an expression that didn't exist.
So we need to actually handle that.
So we're going to do compiler error.
Lex Process compiler and we're going to say you closed an expression that you never opened
and yeah, that should be fine.
And yeah, that should be it for our lex finish expression.
And yeah, you'll know that we don't actually set the parenthesis buffer to any of the tokens yet.
We will get to that eventually, but we're not doing that right now.
So yeah, just scroll down and just by here we're going to say symbol case break token equals token,
make symbol and we're going to make that function now.
So just scroll up and just by here we're going to say static struct token, token, make symbol
and we're just going to pick ahead.
So we're going to say char C equals peek C and we're going to say if the if the character is the right
bracket, then we need to close the expression.
So we're just going to go Lex finish expression just like that.
We're then going to read the actual character.
So we're no longer peeking.
We're going to read the whole thing.
So just go see equals next see.
And as a matter of fact, why don't we just change peak C to next C and we can just get rid of that.
That makes more sense.
Right?
And then we can just go struct token token equals token create ampersand struct token type equals token
type symbol dot C, val equals C.
So character value C and we're just going to return token.
So that should be it for our symbols.
So let's just make and build that now and test that out.
So open up your terminal and we're going to say make clean, make and just go to test.
Let's see.
Just make some parentheses like that.
Save it, and I'll just do mine.
And we can see everything compiled.
Fine.
So we can see we're now able to parse symbols, which is what matters.
So we haven't actually implemented identifiers yet.
So if we were to do something like function or blah, blah, blah, we can see it says unexpected token.
So our Lex is working perfectly fine, right?
So, yeah, you've now implemented symbols.
Congratulations.