 So we are here doing the CSE 2015 midterm one question number three. Problem number three, which is about writing a predictive recursive descent parser for this grammar. So the first step of this grammar is proving that the grammar supports a predictive parser, which would go through the rules, but we're not going to do that now. And we need to write the functions parse v and parse 2. Come with me later after you're done. I'm recording right now. And I have a meeting at 4.45. Okay. I'm not a new part of it. So yes, the first part. So parse v. We need to write parse v. Okay. Cool. So we have v. Oh. So we need two options. We need to decide between v goes to cb or v goes to little b, big b, little b. Right? So the first thing we need to do is get a token. Right? Cool. So what do you want to check? Is it the rule b goes to cb? So what do I need to check? I don't know. I think you parse c right now. Parse c? But I don't know if it's this rule or this rule. So they check. Would you check for the first of b? I need to not check. The first of b contains both of these firsts. The first of cb, that's what I'm going to do. The first of cb. Okay. Right? Because I already proved in part a that the first of cb is the same from the first of b, capital D, little b. Right? I've already proved that in part a. So I want to check if the t type exists in the first of cb. So what is the first of cb? Would it be just c? I don't know. It would be cb. It would be little bit cb. Right? Well, let's see. Well, let's see. cd and epsilon. Yeah, c. Or d. T type is equal to d. Right? Whose follow? The follow of d. d. A follow of b. Follow of b. Follow of b. Right? Because it's whatever comes after b. I got you. D also comes after b. But we don't know. Actually, that may work. But I don't want to think about that. Because that's going to mess everybody up. So we want to check. Because there is an epsilon that exists in the first of cd. And we cannot check for epsilon. What we can check for, though, is the follow of b. And that's because of the epsilon. Okay. So now I understand. Or b. T type is equal to e. What other follow of b? Oh, z. Okay. I'm looking at the first b. Right? So if it is, then I know I'm in this rule. b goes to cd. So what do I do? So now I need to call part c. What do I have to do first? And why? We should un-get-token. Un-get-token why? Just because you do the follow. That's the only reason. Because the follow. Because we just read a cd or an e. Does this rule produce a cd or an e? This rule. Right here. No. b goes to cd. This rule itself does not produce a little c or a little d. No. That's going to come from either c's or d's. Or after us even for an e. So you basically say we always call un-get-token. Well, we can't attempt non-terminal. First. All right. We need to call it. We only want to consume a token when our rule produces that token. Okay. Like here we want to, as we'll see in the other clause, we actually want to consume that b token because that came from this rule. And then we're going to call parse d. And then we're going to want to consume that d. So I'll like to summon token when it comes from that rule. Yes. Okay. That's everything. So we call un-get-token. And then we parse this rule. So we want to say parse c. And if that returns correctly, we will parse d. And we print out a b goes to c d. That makes sense. So else is going to do the other check. If. Right. So what do we need to check? First of all, d, d, b. Yep. d, d, b. So what's that first set? B. So that's if t-token goes b. And do I need to check the follow? Because there's no epsilon. You said only if it's epsilon. There's no epsilon in my mind. And by part one, we already proved that we know that there exists an epsilon in here. That means there must not exist an epsilon in here because it's a predictive grammar. So we know that epsilon cannot exist both on this side and this side. Now, is this a coincidence that when you check the first of c d, there was c d here in that b. And in this case, it was only b. Yes. Because all of these, this first set of b, right, is the first set of this union with the first set of this. Okay. So it's not a coincidence. Nope. Okay. That's something that worked. Okay. So if it's a b, now I know I'm trying to parse this rule. So do I call unget token? No. Because now d came from unget token rule. So it's called get token. So now I want to call parse d, right? Oh. Okay. And now when d returns, now I need to make sure that the next token is a b. So you check again. Exactly. And then here, so I have t type equals to get token. Now I want to think about, so now I want to check if t type equals b, right? Yeah, there's two ways you can do it. I mean, if t type, so look at this, if t type equals b, then I print. And that's b goes to about little b, capital b, and then b. L, so what if it's not that way? This is syntax error, right? Yep. I remember that. And they're not quite done. So we finish this if, this if else. So what if none of these are true? Just tell us syntax error, right? It's going to be a syntax error, right? There's none of them. So what in the case where you actually print epsilon? What's the next one? Is the next one print? Yeah. See? We have time to do that? Yeah. It's just fine. Because this is recorded. So I can look at multiple gigabytes of it. That's a fair idea. It's a young ass. Yeah, this is good enough. Because I'm talking through it, so if I could just listen to the recording again, I was here. I don't know those poor people who aren't here. They're watching on someone. They're not here by everybody. Just so you know. One in the video, like a minute. Throw in the video and then we'll be good to go. Okay, part C. So now we've got a part C, so we always need to get the token. T time. Let's get tokens. Cool. I have two different rules. I'm going to check the first rule. So if, what am I checking? Now we're checking the first of little C, big C. Yep. And say T time equals C, little C. And you, the part C. And do I want to call and get token? No, because there's not so much. But do we part C? Because it's the same. Okay, I guess you're right. So we part C. Yeah, right. So it's recursive. I was going to keep doing this. But look, every time we call part C, we have consumed a token. We've consumed a C from the input. So it's not, we're not going to infinitely loop because we're moving through the output. Okay, yes, that makes sense. Because next it won't be C. Exactly. And then eventually, this next rule will kick in. So then what's the else of this? Else of what? Else of, now it's checking for the first of Epsilon. I mean, the first of the second rule. So there's, so I'm checking here. So I want to check the first of Epsilon, which is Epsilon. But we know I can't check Epsilon. So what do I do if there's an Epsilon in the first set? Yeah, so Epsilon, you check and follow. Yes. So it's always the follow of the rule. Yes, a lot to answer. Okay. So that's, so now we check if it's D or E. Now if it is. Now if it is. What do we do with that token? Do we ungate it or not? We ungate it because it's a follow. Yes. And because this didn't come from us, right? We generated nothing. Right, that came from. We've got a D or an E. That came from after us, right? So we know we need, we know we have to put it back. Oh, here I'd print. Oh, okay. All right. Print. C goes a little C fixy. Okay. So ungate token, then I print. And this is what you say C goes after. Yep. C goes hard. Everything's hard until it's easy. That's true. I'll take your understanding. And now. And then else. Else would be syntax error. Yep. And this is part of. That's this if else, right? And so, yeah, you can see the recursion here, right? Every time this goes, when we keep reading Cs, we keep creating the rule C goes to big C low. Big C. Big C. We keep parsing that. And then at one point we'll read a D or an E so we know that C chose the transition of C goes to epsilon. Okay. So we can stop parsing that and our call stack goes all the way back. Okay. All right. Yes. So then we ungate tokens if we do a follow. Okay. Let me stop this for a second. Okay.