Topic10- Type of Grammar

download Topic10- Type of Grammar

of 14

Transcript of Topic10- Type of Grammar

  • 8/3/2019 Topic10- Type of Grammar

    1/14

    Type of Phrase Structure Grammar

  • 8/3/2019 Topic10- Type of Grammar

    2/14

    Unrestricted Grammar (Type 0)

    A grammar G = (V, T, S, P) is unrestrictedif it has no conditions are imposed on theproductions, which are of the form x y,

    where x

    (V

    T)

    +

    and y

    (V

    T)* a combination of one or more vocabulary

    denoted by xcan be replaced by acombination of zero or more vocabulary

    denoted by y Exception: does not appear on the left side

    of a production

  • 8/3/2019 Topic10- Type of Grammar

    3/14

    Context-sensitive Grammar (Type 1)

    A grammar G = (V, T, S, P) is context-sensitive if everyproduction is of the form pAq pyq, where A V; p, q

    (VT)* and y (VT)+

    a variable Aoccurring in the context of string ponthe left and qon the right can be replaced by acombination of one or more vocabulary denoted by y

    the substitution of the variable on the left of aproduction is context sensitive, i.e., A y

    does not appear on both the left and right side of a

    production; so,G cannot generate a languagecontaining null string

    therefore, the derivation is non-contracting, i.e.,| pAq| | pyq|

  • 8/3/2019 Topic10- Type of Grammar

    4/14

    Context-free Grammar (Type 2)

    A grammar G = (V, T, S, P) is context-free

    if every production is of the form A y; A

    V and y (VT)*

    a singlevariable Acan be replaced by a

    combination of zero or more vocabularydenoted by y

    the substitution of the variable on the left of a

    production is context insensitive, i.e., it doesnot depend upon the rest of the symbols inthe string

  • 8/3/2019 Topic10- Type of Grammar

    5/14

    Regular Grammar (Type 3) A grammar G = (V, T, S, P) is a regular grammar if every

    production is of the form:

    A xB(c.f. Grammar Type 2)A xA

    where A, BV and xT

    Note that A, Bare variables, and xis strictly a singleterminal symbol

    is a context-free grammar

    e.g. G = ({S, A}, {a,b}, S, {S bA | a | , A aA | bA | b})

    Regular grammar is concise way to describe a formallanguage

  • 8/3/2019 Topic10- Type of Grammar

    6/14

    Classification by Noam Chomsky

    A grammar that has no restriction on itsproduction is called type-0 grammar

    A grammar in which every production is ofthe form |w1| |w2| or the form w1, iscalled type-1 grammar.

    A grammar in which every production is of

    the form w1w2, where w1 is a single non-terminal, is called type-2 grammar

  • 8/3/2019 Topic10- Type of Grammar

    7/14

    Classification by Noam Chomsky

    A grammar in which every production is ofthe form w1w2, where w1 is a single non-terminal symbol and w2 is a single terminalor a terminal followed by a non-terminal orof the form S, called type-3 grammar ora regular grammar.

    From the definition given, it is obious that every

    type-3 grammar is a type-2 grammar,every type-2 grammar is a type-1 grammar andevery type-1 grammar is a type-0 grammar.

  • 8/3/2019 Topic10- Type of Grammar

    8/14

    Phrase Structure Grammar

    Phrase structure grammar can also beclassified according to another criteria asfollows:

  • 8/3/2019 Topic10- Type of Grammar

    9/14

  • 8/3/2019 Topic10- Type of Grammar

    10/14

    Backus-Naur Form(BNF)

  • 8/3/2019 Topic10- Type of Grammar

    11/14

  • 8/3/2019 Topic10- Type of Grammar

    12/14

  • 8/3/2019 Topic10- Type of Grammar

    13/14

  • 8/3/2019 Topic10- Type of Grammar

    14/14