Explain Type-2 and Type-3 Grammar in TOC?

Data Structure AlgorithmsComputer ScienceComputers

The Chomsky hierarchy is given below −

Type 2 − Context Free Grammar (CFG)

  • Type 2 grammars are generated by context free languages.
  • The language that is generated by the grammar is recognized by Push Down Automata.
  • Type 2 must be in Type 1.
  • Left-hand side of production can have only one variable.
  • |alpha| =1

    There is no restriction on beta.

    The production rules are in the form of −

    A->alpha

    Where, A is any single non-terminal and is any combination of terminals and nonterminals.

Example

S->AB

A->a

B->b

Type 3 − Regular grammar

  • Type 3 grammars are generated by regular languages.
  • These languages are exactly all those languages that can be accepted by finite state automata.
  • Type 3 is the most restricted grammar.
  • It is in the form of

    V->VT*/T* Or V->T*V/T*

Example

S->ab

raja
Published on 16-Jun-2021 12:50:21
Advertisements