1. Gyanastra
  2. Theory of Computation
  3. Regular Expressions
  4. Regular Grammars (Right Linear and Left Linear)
Free lesson, no account needed 4 min read 10 practice questions after it
Asked in past papers10 times
  • GATE CSE2015200520041990
  • UGC NET201720162014201320092006

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 A→aBA \to aB or A→aA \to a, i.e. the nonterminal sits at the right end.
  • Left linear grammar: every production has the form A→BaA \to Ba or A→aA \to a, i.e. the nonterminal sits at the left end.
  • Here A,BA, B are nonterminals and aa 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

  1. Start from the class of regular languages.
  2. Grammars that generate regular languages are called regular grammars; each one is either right linear or left linear.
  3. A regular language can be represented mathematically by a regular expression (the representor), just as a finite automaton accepts it (the acceptor).
  4. The study of regular expressions begins with how a regular language is represented using these representors.

Formulas

  • A→aBA \to aB — right linear production: nonterminal BB at the right end (A,BA, B nonterminals, aa a terminal or the empty string).
  • A→aA \to a — terminating production in a right linear grammar.
  • A→BaA \to Ba — left linear production: nonterminal BB at the left end.
  • A→aA \to a — terminating production in a left linear grammar.

Comparison

Description methodNameRole
Finite automatonAcceptorAccepts the strings of a regular language
Regular expressionRepresentorMathematically represents a regular language
Regular grammar (right linear / left linear)GeneratorGenerates 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 (A→aBA \to aB); left linear puts it at the left end (A→BaA \to Ba).
  • Both types allow the terminating form A→aA \to a.
  • 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 XiX_{i} = 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. nan_{a} and nbn_{b} 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 (e.g.anbn)(e.g. a^{n} b^{n}) 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
Pages 1–2 of 2