Regular expressions and conversions
Regular expressions, finite automata and consistently left- or right-linear grammars describe the same language class. Convert between representations by preserving the language, not by matching the appearance of a diagram.
2.1 Expression semantics and identities
Past papers · CS 2014–2026 (23 papers): 4 questions, 5 marks
The basic expressions are , and symbols . Build expressions using union, concatenation and star. Precedence is star, then concatenation, then union. Parentheses override precedence. In a regex, denotes the singleton language .
| Requirement over | One expression or construction |
|---|---|
| Ends in a fixed string | |
| Contains a fixed string | |
| Exactly one | |
| Odd number of symbols | |
| Even number of symbols | |
| Contains both and | |
| Avoids a fixed pattern | Complement the complete DFA for containing it |
2.2 Arden equations
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
Write one equation for each state's accepted continuations. Include at accepting states. A transition labelled from state to state contributes to .
2.3 State elimination and regex to NFA
Past papers · CS 2014–2026 (23 papers): 7 questions, 10 marks
For regex to -NFA, give a symbol an entry-to-exit edge, give an empty-move edge, and give no path. Union branches through new entry and exit states. Concatenation joins the first exit to the second entry. Star adds an empty bypass and a repeat edge. The construction uses a number of states linear in expression size; determinisation may then be exponential.
The extra term enters , loops there any number of times and exits. Preserve all old labels while computing one elimination step. Different elimination orders can produce different-looking equivalent expressions.
2.4 Regular grammars
A right-linear grammar uses , and optionally ; finite terminal strings may replace single after expansion. A left-linear grammar uses , and optionally . Use one orientation throughout. A grammar with at most one variable anywhere on a right-hand side is linear, but need not be regular: is linear and generates a nonregular language.
Convert a right-linear grammar to an NFA by making variables states. A rule gives an edge; goes to a new final state; makes final. The start variable becomes the start state. Reverse this construction to obtain a right-linear grammar from an NFA.
Last-minute recall
- Regex equality means language equality.
- Star binds more tightly than concatenation and union.
- Arden's multiplication side determines where the star goes.
- The no- condition gives Arden uniqueness.
- State elimination includes all loops through the removed state.
- A linear grammar need not be a regular grammar.