Theory of Computation · Regular Expressions
Regular Languages, Acceptors, and Generators
Overview
Regular languages form a class of simple pattern-based languages, and they can be described in two dual ways: by acceptors, which decide whether a single string belongs to the language, and by generators, which enumerate all strings of the language.
For regular languages these two roles are filled exactly by finite automata and regular grammars respectively.
Key concepts
- Regular languages: a class (family) of languages that includes all the simple pattern-based languages, such as the set of all strings of length 2, of length , of length , strings starting with a, ending with b, starting with ab, and the set of binary numbers divisible by 2, divisible by 3, and so on.
- Acceptor: a mathematical representation to which a string is given and which answers either yes (the string is in the language) or no (the string is not in the language).
For regular languages, the acceptors are exactly the finite automata. - Generator: works the other way round — given a language, it generates (enumerates) all the strings in the language. No particular string is asked about; all strings present in the language are produced.
- Grammars: generators are nothing but grammars. For regular languages, the grammars that generate regular languages are called regular grammars.
How it works
- An acceptor takes one string as input and returns a membership decision (yes/no); it does not list the language.
- The finite automata (acceptors for regular languages) are of two kinds:
- With output: Mealy machines and Moore machines.
- Without output: DFA, NFA, and epsilon-NFA.
- DFA, NFA and epsilon-NFA are all equivalent in power and accept exactly the regular languages; Mealy and Moore machines are finite-state machines with output (transducers), not acceptors.
- A generator takes the language as a whole and produces every string in it. For example, let L1 be the set of all strings starting with a (a, aa, ab, and so on).
Given the single string "abb", asking "is abb in L1?" is a job for an acceptor, which answers yes or no. Asking "give me all the strings of L1" (enumerate the whole language) is a job for a generator. - Generators are grammars; for regular languages, the grammars that generate regular languages are called regular grammars.
Worked examples
Acceptor vs generator on L1
- Let L1 = set of all strings starting with a: a, aa, ab, ...
- Input string: abb.
- Using an acceptor: feed abb to the finite automaton → it answers yes (abb starts with a, so abb is in L1).
- Using a generator: supply no string; the grammar for L1 produces the entire language: a, aa, ab, aaa, aab, aba, abb, ...
Comparison
| Aspect | Acceptor | Generator |
|---|---|---|
| Input | One string | The language itself (no string supplied) |
| Output | Yes / No (membership decision) | All strings of the language (enumeration) |
| Mathematical form for regular languages | Finite automata without output (DFA, NFA, epsilon-NFA) | Grammars (regular grammars) |
| Example question answered | "Is abb in L1?" | "List all strings of L1" |
| Finite automata (acceptors) | Subtypes |
|---|---|
| With output | Mealy machine, Moore machine |
| Without output | DFA, NFA, epsilon-NFA |
Revision summary
- Regular languages include strings of length 2, length , length , strings starting with a, ending with b, starting with ab, and binary numbers divisible by 2, 3, etc.
- Acceptor = given a string, answers yes/no about membership;
acceptors for regular languages = finite automata. - Finite automata with output: Mealy and Moore (equivalent to each other as transducers); without output: DFA, NFA, epsilon-NFA (all equivalent as acceptors of regular languages).
- Generator = given a language, generates/enumerates all its strings;
generators = grammars, and for regular languages they are regular grammars. - Remember the pairing: regular language → acceptor is a finite automaton; regular language → generator is a regular grammar.
Previous-year exam insights
- Every regular language is also a context-free language (and hence context-sensitive, recursive, recursively enumerable); the converse fails.
So any construct describable by a regular expression is describable by a CFG, but not every CFL is regular.
Asked inUGC NET 2009UGC NET 2017 - A finite-state machine (finite automaton) recognizes exactly the languages generated by regular (type-3) grammars; regular grammars, regular expressions, DFAs/NFAs and ε-NFAs are all equivalent formalisms for regular languages.
Asked inUGC NET 2017 - In compiler construction the pairing is: lexical analysis is specified by regular expressions and implemented by finite automata (DFA/NFA); syntax analysis is specified by context-free grammars and implemented by pushdown automata.
Asked inUGC NET 2017 - A regular grammar is a type-3 grammar in Chomsky hierarchy: right-linear (A → aB or A → a) or left-linear (A → Ba or A → a) productions only; mixing right-linear and left-linear productions in one grammar can generate non-regular languages.
Asked inUGC NET 2017 - Regular languages are closed under union, intersection, complement, concatenation, Kleene star, reversal and homomorphism (and under substitution by regular languages, but not by arbitrary languages).
They are closed under intersection with regular languages, not with an arbitrary language: Σ* ∩ { } is not regular.
(It is the context-free languages that are closed under intersection with a regular language.) - A language is regular iff it is accepted by some DFA iff it is accepted by some NFA iff it is denoted by some regular expression iff it is generated by some regular grammar; pumping lemma gives a necessary (not sufficient) condition for regularity.