Explain type 2 grammar with properties


Type 2 grammars are context free grammars (CFG).

All productions are of the form −

A → x — where A is nonterminal, x is a string of nonterminal and terminals,

A context-free grammar is equivalent to a pushdown automaton (PDA) and to context free languages.

Example − Pushdown Automaton (PDA)

Properties

  • A grammars, G = (V, T, P, S) is said to be context free if the production rule is of the form, A → α .

  • The transition allows A → ε [i.e., α → ε] where, A is a non terminal symbol α is any terminal or non-terminal symbol.

  • Here, the left hand side of the transition rule consists of only one non-terminal.

  • Type 2 grammars are the basis of the syntax of most programming languages such as XML. Properties

The CFG is closed under the following −

  • Union

  • Concatenation

  • Kleene closure

It is not closed under complementation, substitution, reversal.

Example

Consider the production, P ⇒ {S → aSa, S → bSb, S → ε}

Since S → aSa
   → aaSaa [as S → aSa]
   → aabSbaa [as S → bSb]
   → aabbaa [as S → ε]

Thus, S may generate S = {ε, aa, bb, abba, aabbaa, abaaba, …}

Thus, the language is defined as L(G) = {w wR | w ε {a, b}*}

CFG can be handled using the pushdown automaton that uses stack memory to store the symbols.

Updated on: 15-Jun-2021

846 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements