Theory of Computation · Regular Expressions
Regular Grammars (Right Linear and Left Linear)
Overview
Regular grammars are grammars that generate exactly the class of regular languages.
They come in two forms, right linear and left linear, and together with finite automata (acceptors) and regular expressions (representors) they give the three ways of describing a regular language.
Key concepts
- Regular grammar: a grammar that generates a regular language. Regular grammars generate exactly the class of regular languages.
- Right linear grammar: every production has the form or , i.e. the nonterminal sits at the right end.
- Left linear grammar: every production has the form or , i.e. the nonterminal sits at the left end.
- Here are nonterminals and is a terminal (or the empty string).
- Every regular grammar is either right linear or left linear.
- Acceptor: a finite automaton, which accepts the strings of a regular language.
- Representor: a regular expression, a mathematical expression that represents a regular language.
- Generator: a regular grammar (right linear or left linear), which generates a regular language.
- Linear grammars in general are a broader class; regular grammars are the regular-language case.
How it works
- Start from the class of regular languages.
- Grammars that generate regular languages are called regular grammars; each one is either right linear or left linear.
- A regular language can be represented mathematically by a regular expression (the representor), just as a finite automaton accepts it (the acceptor).
- The study of regular expressions begins with how a regular language is represented using these representors.
Formulas
- — right linear production: nonterminal at the right end ( nonterminals, a terminal or the empty string).
- — terminating production in a right linear grammar.
- — left linear production: nonterminal at the left end.
- — terminating production in a left linear grammar.
Comparison
| Description method | Name | Role |
|---|---|---|
| Finite automaton | Acceptor | Accepts the strings of a regular language |
| Regular expression | Representor | Mathematically represents a regular language |
| Regular grammar (right linear / left linear) | Generator | Generates a regular language |
Revision summary
- Regular grammars generate exactly the regular languages — no more, no less.
- There are only two types of regular grammar: right linear and left linear.
- Right linear puts the nonterminal at the right end (); left linear puts it at the left end ().
- Both types allow the terminating form .
- A regular language has an acceptor (finite automaton) and a representor (regular expression).
- Regular expressions are mathematical expressions used to represent a regular language.
- Linear grammars in general are a broader class; regular grammars are the regular-language case.
Previous-year exam insights
- A right-linear grammar is converted to an NFA by making each nonterminal a state, the start symbol the initial state, adding a final state F, turning A → aB into δ(A,a)=B, A → a into δ(A,a)=F, and A → ε into A being final;
the reverse construction (DFA → right-linear grammar) uses A → aB when δ(A,a)=B and A → ε for each final state.
The minimum DFA size is then found by standard minimization.
Asked inGATE 2005GATE 2004 - A left-linear grammar is converted to an NFA by reversing the productions: A → Ba becomes B → aA and A → a becomes S → aA (with a new start symbol), i.e. reverse the language, build the right-linear automaton, then reverse the automaton.
Asked inGATE 2004UGC NET 2014 - A system of right-linear grammar equations = aX_j + ... + {λ} is solved by treating each nonterminal as a language variable and applying Arden's lemma: the solution of X = AX + B (A not containing ε) is X = A*B;
substitute and eliminate variables to get the regular expression for the start symbol.
Asked inGATE 2015 - To design a regular grammar for a language described by parity/counting conditions (e.g. and both even, n+m even), use one nonterminal per residue class of the counts (mod 2 states), with the start state's nonterminal producing ε if the empty string is in the language; the grammar is right linear with one nonterminal per DFA state.
Asked inUGC NET 2016UGC NET 2014UGC NET 2013 - Regular grammars generate exactly the regular languages, so they are recognized by finite automata and described by regular expressions; context-free and context-sensitive languages need strictly more powerful grammars/automata (pushdown automata, linear-bounded automata).
Asked inUGC NET 2017 - Lexical analysis is specified by regular expressions/regular grammars and implemented by finite automata; syntax analysis is specified by context-free grammars and implemented by pushdown automata.
Asked inUGC NET 2017