CSCD 420 Nov 20 2026
Overview
The lesson develops the FIRST and FOLLOW sets used to guide predictive top-down parsing, contrasting that approach with CYK, which can parse any context-free grammar after conversion to Chomsky normal form. It explains recursive and nullable productions, the end-of-input marker $, and how FIRST and FOLLOW information identifies which terminals can begin or follow a non-terminal; an interpreter-versus-compiler analogy provides a brief programming-language comparison.
Key takeaways
- FIRST(X) records terminals that can begin strings derived from X; when a production begins with a nullable symbol, continue through the right-hand side until a non-nullable symbol is reached or the entire production can derive λ.
- FOLLOW(X) records terminals that can immediately follow a derivation of X, and FOLLOW of the grammar's start symbol always contains $.
- For a production A → αBβ, add FIRST(β) without λ to FOLLOW(B); if β can derive λ, also add FOLLOW(A) to FOLLOW(B).
- When a production ends in B, FOLLOW of its left-hand side propagates to FOLLOW(B), including through recursive chains of productions.
- FIRST and FOLLOW sets support predictive top-down parsing for suitable grammars, while CYK remains applicable to any context-free grammar after conversion to Chomsky normal form.
- Interpreters execute translated instructions incrementally, while compilers translate a complete program before execution; these are implementation choices rather than inherent properties of Python, Java, or any other language.
Chapters
- Homework 9 is due in two weeks and is the last homework, aside from the project and final exam.
- Exam 3 is scheduled for the day after Thanksgiving break, with review sessions planned for Monday and Tuesday beforehand.
- The final is scheduled during finals week; students with a scheduling conflict should contact Chris Cain.
- FIRST of a non-terminal is the set of terminals that can begin strings derived from that non-terminal.
- The worked grammar shows how to combine FIRST sets across productions, including recursive dependencies between non-terminals.
- Remove useless productions before calculating FIRST so the sets reflect symbols that can actually participate in derivations.
- CYK works for any context-free grammar after conversion to Chomsky normal form, while the more efficient top-down method applies only to some grammars.
- An interpreter translates instructions one at a time and passes each translated instruction to the mechanic for immediate execution.
- A compiler translates the complete instruction list before execution, requiring preparation time but enabling the mechanic to run the instructions quickly as a batch.
- The analogy highlights the interpreter's immediate feedback and the compiler's faster execution after translation.
- A programming language itself does not dictate whether it must be interpreted or compiled; either implementation strategy can be built for a language.
- Interactive data analysis can benefit from interpreting code step by step and examining intermediate results.
- Programs for embedded hardware are often compiled so they can run autonomously without an operator monitoring each step.
- A grammar with a recursive production illustrates why FIRST sets are calculated as unions that can refer back to the set being defined.
- When a production begins with a terminal, that terminal belongs in the left-hand non-terminal's FIRST set regardless of later expansions.
- If every derivation from a non-terminal must eventually begin with B, a recursive reference alone does not add other terminals.
- Define FIRST(λ) as containing λ, and record λ in a non-terminal's FIRST set when that non-terminal can derive the empty string.
- For a production beginning with a nullable non-terminal, continue to the next symbol and add its FIRST set as well.
- The example derives strings beginning with a, b, c, and d by using a nullable B before a non-terminal A.
- Deriving a sample string for every terminal in a proposed FIRST set can verify included elements, though it cannot prove that no elements are missing.
- FOLLOW of a non-terminal contains terminals that can immediately appear after a derivation of that non-terminal.
- The start symbol's FOLLOW set always includes $, the marker for the end of the input string.
- A terminal directly after a non-terminal in a production can be added to that non-terminal's FOLLOW set.
- FOLLOW information helps predictive parsing choose among possible expansions.
- When a production's right-hand side ends in a non-terminal, add the left-hand side's FOLLOW set to that final non-terminal's FOLLOW set.
- The propagation rule follows from expansions: anything that can appear after the left-hand side can also appear after the final non-terminal.
- Recursive derivations may require applying FOLLOW relationships across multiple levels of non-terminal expansions.
- Concrete derivations help explain why a terminal after an expanded left-hand side can also follow a non-terminal at the end of its production.
- For a production with a non-terminal followed by a suffix, add the suffix's FIRST terminals, excluding λ, to the non-terminal's FOLLOW set.
- If the suffix can derive λ, also add the production's left-hand side FOLLOW set to the non-terminal's FOLLOW set.
- In the worked grammar, FOLLOW of the start symbol includes $, while other FOLLOW sets are built by examining each non-terminal's position on production right-hand sides.
- Checking a FOLLOW result with sample sentential forms can confirm that each listed terminal occurs after a derivation of the relevant non-terminal.
- The class calculates FOLLOW by first listing every occurrence of each non-terminal on production right-hand sides, then handling direct terminals, suffixes, and end positions.
- A recursive occurrence such as a non-terminal followed by itself contributes no new terminals by itself, because it only refers back to the same FOLLOW set.
- When a non-terminal is followed by S, its FOLLOW set receives FIRST(S); the example's FIRST(S) contains B, A, C, and D.
- When B is followed by A, FIRST(A) contributes C and D; λ matters when it allows the scan to continue to later symbols in a suffix.
Transcript excerpt
0:03 We're in the process of revealing a new assignment. That assignment will be due in two weeks rather than one. It would be especially cool of me to have something do on Thanksgiving. That would be really bad. >> Are you talking about >> Oh, we're going to leave? Sorry. >> Are you talking about homework nine? >> Yeah. >> Oh. >> Yeah, homework nine will be due in two weeks. So over the last week of instruction, and that will be the last homework. Aside from of course the project and the final exam that are still coming. But yeah, exam three is going to be the day after Thanksgiving break. We'll be reviewing Monday and Tuesday of next week. So please come prepared with questions. I do have some practice problems for us to work on to fill out some of that time as well.
0:49 >> And you said there's a final on finals week? >> Yeah. Yeah, finals on finals week. And if that does not work with your schedule for some reason, reach out to me and we can figure something out. All right, last time we were going over the first function. To further motivate that, we needed a a couple of functions in our back pocket to be able to handle what we're going to talk about, which is a new even more efficient top-down parse that works sometimes. The reason we learn CYK is it works all of the time, no matter what the context-free grammar is. We can always convert it into Chomsky normal form, which means that we can use CYK on it. But there are some grammars that have a property that we will talk about in the not too distant future where even more
1:38 efficient parsing in advance is
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Chris Cain.