CSCD 420 Oct 15 2026
Overview
Chris Cain reviews regular expressions and context-free grammar construction, emphasizing how to encode exact or bounded symbol counts, inequalities between counts, language operations, and modular string lengths. The class then connects lambda-NFA subset construction with regular grammars, working through exam-oriented methods for handling lambda transitions and converting left- or right-linear productions into automata.
Key takeaways
- Exact symbol counts in regular expressions require excluding that symbol from every wildcard section; otherwise the expression may accidentally admit extra occurrences.
- Optional-symbol positions provide a direct construction for “at most k” occurrences: use k slots, each offering the symbol or λ, with other alphabet symbols between slots.
- A grammar for AⁿBᵐ with n > m can generate matched A/B pairs recursively but must terminate with at least one extra A.
- Language operations can often be simplified before constructing a grammar: L1 ∪ L2 equals L1 when L2 ⊆ L1, and L1 minus the complement of L4 equals L4 when L4 ⊆ L1.
- Lambda-NFA conversion must compute λ-reachable states both when forming the DFA’s initial state and after each consumed input symbol.
- Right-linear grammars translate to NFAs by making nonterminals states and expanding multi-symbol terminal sequences into intermediate states; left-linear grammars require reversing the construction direction.
Chapters
- For strings over {A, B, C} containing exactly two A’s, place two required A symbols in the expression.
- Use arbitrary-length repetitions of B or C before, between, and after those A’s.
- Exclude A from the surrounding repetitions so the expression cannot generate a third A.
- Build three possible A positions, each written as A or λ, with arbitrary B/C strings between positions.
- Choosing λ in all three positions generates strings with no A’s; choosing one or more A alternatives gives up to three.
- Multiple derivations may generate the same string, but ambiguity does not change the language recognized.
- Represent arbitrary substrings over {A, B, C} with the shorthand Σ*.
- Enumerate all six possible first-occurrence orders of A, B, and C, such as A-B-C and C-B-A.
- For each order, concatenate Σ* sections around the required symbols, then union the six expressions.
- Cain gives students time to work through grammar-construction exercises before discussing solutions.
- The problems are general grammars, not necessarily regular grammars, matching the scope of the first assignment.
- The class shifts from regex design to identifying constraints that a grammar must enforce.
- For strings in the form AⁿBᵐ with n > m, the grammar must preserve the order of all A’s before all B’s.
- Use recursive productions that add a matched A/B pair while maintaining at least one extra A.
- A separate terminating step must produce at least one A, preventing derivations with equal counts.
- To generate L1*, allow completed L1 strings to repeat by returning to the start of the L1 construction.
- Separate the choice of producing zero repetitions (λ) from the recursive process that generates a valid L1 string.
- Putting λ directly on the count-preserving recursion can incorrectly permit equal numbers of A’s and B’s within a nonempty repetition.
- For L1 ∪ L2, create a new start symbol with alternatives to the start symbols for each language, keeping nonterminal names distinct.
- If L2 is a subset of L1, the union simplifies to L1 and a separate L2 grammar is unnecessary.
- When L4 is a subset of L1, L1 minus the complement of L4 reduces to L4, avoiding a more complicated grammar construction.
- For concatenation L1L2, use a new start production that places the L1 grammar’s start symbol before the L2 start symbol.
- For L1³, concatenate three copies of the L1 start symbol in the new start production.
- For strings of A’s whose length is nonzero modulo 3, recurse in groups of three A’s and terminate with either one or two additional A’s.
- In subset construction, include every state reachable through λ-transitions without consuming an input symbol.
- A λ-edge from Q0 to final state Q2 makes the DFA start state the set {Q0, Q2}, which is accepting.
- When processing an A, follow A-edges from every state in the current set and include λ-reachable states; missing transitions lead to the trap state.
- A right-linear grammar maps nonterminals to states; terminal sequences longer than one symbol are expanded into intermediate states.
- A production with a terminal followed by the same nonterminal creates a labeled self-loop, while a terminating production leads to a final state.
- For a left-linear grammar, reverse the construction direction, beginning from a final state and working back toward the start state.
- A grammar must consistently keep its nonterminal on the right or left to be linear; an inconsistent production is not a regular grammar rule.
Transcript excerpt
0:02 get started. >> So, I at least want to start by going over the remainder of the regular expression practice problems that we started last time. Who would like a little bit more time to work on these or did you get a chance to work on these last night? Sounds like people want to go over them then. We can do that. So, we did seven and eight at the end of class, but we need to do 19 A, B, and C. So, anyone want to give me a How did you think about 19A?
0:52 What's the What's the brain's not working today? High level thought process I guess of of how you tackle it. >> Yeah. It's like anything followed by an A followed by anything followed by an A followed by anything. >> Yeah. The anything being anything in the alphabet. In this case, the alphabet's A, B, and C. So we need to put those two A's that we know are there and what can come before the first A is an arbitrary number of A's or B's or C's between them A's or B's or C's after an arbitrary number of A's or B's
1:40 or C's except oh yeah it's exactly two A's. So we can't have any A's here. No A's. No A's. No A's. There we go. Yeah, if this were two or more A's, then we would want that. But exactly two A's, I want these pluses either. Any arbitrary number of these are before the first, between the two, or after the last. Any questions on A? How did we handle B? B is a little interesting. Now we're saying no more than three A's. So we need some way of specifying all of those possibilities. Yeah, >> similar to A, but in the last one it
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.