CSCD 420 Dec 02 2026
Overview
The class moves from LL(k) parsing to LR parsing, showing how lookahead requirements depend on grammar structure and how an LL(5) table can grow to 364 columns over the alphabet A, B, C, and the end marker. LR parsing combines shift and reduce operations with dotted items, recursive closure, and a DFA to parse more grammars in linear time than LL parsing, though its construction requires substantial space and bookkeeping.
Key takeaways
- For an alphabet of three terminals, an LL(5) table needs 364 lookahead columns when shorter inputs are included through end-marker padding.
- A context-free grammar can fail to be LL(k) for every fixed k when its alternatives share arbitrarily long prefixes, even if the language has a more efficiently parseable grammar.
- CYK parsing takes cubic time, while LL and LR parsing provide linear-time parsing when the grammar meets their respective conditions.
- LR items use a dot to record how much of a production has been recognized, and closure recursively adds productions that may reduce to the next required nonterminal.
- LR parsing combines a DFA of item sets with stack operations; back pointers let the parser reverse transitions during reductions without rescanning the input.
Chapters
- The final homework assignment is due tonight, with a possible one or two day extension depending on students' needs.
- The project is due next week, and the final exam study guide is available.
- Friday is planned for final review and possibly returning Exam 3 for discussion.
- For nonterminal B, the productions begin with distinct terminals A and B, so one character of lookahead is sufficient.
- For C, the alternatives share an initial A, so a two-character lookahead distinguishes them.
- For S, the alternatives can share four characters, requiring a fifth character to distinguish their productions.
- With terminals A, B, and C, five-character lookahead strings account for 3^5 possibilities.
- Shorter strings padded by the end marker add 3^4 + 3^3 + 3^2 + 3 + 1 possibilities.
- The resulting LL(5) table has 364 columns, or more than 1,000 cells for a grammar with three nonterminals.
- A grammar with alternatives that can generate arbitrarily long shared runs of A cannot be disambiguated by any fixed amount of lookahead.
- Equivalent languages can have grammars with different LL(k) properties because production structure affects how much lookahead parsing needs.
- Removing one redundant production does not necessarily fix the example: recursive alternatives can still generate the same long A prefixes.
- When a grammar cannot be parsed efficiently as LL(k), conversion to Chomsky Normal Form and CYK parsing is an option, but CYK takes cubic time rather than linear time.
- LR parsing uses a bottom-up process, reducing right-hand sides to their production's left-hand side.
- More grammars are LR than LL, making LR a useful alternative before resorting to CYK.
- The lecture models LR parsing with an NPDA: reduction transitions replace matching right-hand sides, while shift transitions consume input and update the stack.
- The parser shifts input symbols onto the stack and reduces matching right-hand sides, as in the example string ABCAB.
- At some positions, both shifting and reducing appear possible, so the parser needs additional information to choose deterministically.
- A reduction can involve multiple stack symbols, a capability that the basic NPDA stack model cannot inspect directly.
- An LR item places a dot within a production to mark which symbols have been recognized on the stack.
- For an item such as S → AS · B, the stack has matched AS, while B remains to be recognized.
- A dot at the end of a production indicates that its right-hand side is ready to reduce to the left-hand side.
- When an item has its dot before a nonterminal, closure adds items for that nonterminal's productions with the dot at the beginning.
- The closure of S → A · SB includes items for S's possible productions, then recursively adds items for any newly encountered nonterminals.
- Closure records possible ways to reach a needed nonterminal through reductions, trading greater space use for efficient parsing decisions.
- Each DFA state represents a set of LR items, and an edge labeled with a symbol records progress past that symbol.
- The construction starts with an augmented start production, then expands states by calculating closures and reusing states with identical item sets.
- The DFA works alongside the NPDA stack, with states tracking parse progress and back pointers preserving the path needed for reductions.
- The example parse follows DFA transitions for A, B, and C, then reduces C to A when the corresponding item reaches the end of its production.
- Later reductions pop stack symbols and follow stored back pointers to identify the correct earlier DFA states.
- The parse eventually reduces the stack to the augmented start symbol and accepts; the method remains linear in input length despite the large DFA.
Transcript excerpt
0:03 All right, so announcements. I made most of them a minute ago, but a couple of people have arrived since then. So time running out. We only have through Friday before we have a Wednesday exam for during our final slots in here next week. We have a last homework assignment that is due tonight. I can depending on how difficult it is to get that in by night, I may be for extending that a day or two depending on needs. I know we've been covering some of the material the last couple of days that have been on that. So I'm especially open to if you're needing a little bit more time depending on how that interfaces with your schedule. Then
0:50 we have a project due next week. Or it's not remotely erased. And we'll see what the rest of this week looks like. I want to get through the last couple slides here of LL parsing and talk about LR parsing. The study guide for the final is up now. So go ahead and take a look at that once you get a second. I will certainly dedicate Friday's class to a review, but I also want to get exam three back to you and go over that depending on how much time we have for that on Friday. We'll have to make a decision about how much of Friday to spend on review how much you get to go over exam three. If we decide to study for the final, then I would have
1:39 the exams available in my office for individual consultation going over it, going over any questions you have about it. So that's I think will take us through the end of the quarter. Anyone have any questions on schedule and upcoming events?
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.