Search code examples
compiler-construction

what is the Chomsky classification of this grammar after reduction ? i'm still confused


this is the grammar before reduction:

This is grammar

my reduction steps is

1- Generation

S -> aC

A -> bSca

C -> ad

2- Reachable

S -> aC

C -> ad

i'm still confused about Chomsky Classification of this grammar


Solution

  • The Wikipedia article on the Chomsky hierarchy provides simple definitions. In particular, it says that a Type 2 (context-free) grammar is:

    defined by rules of the form A → α with A being a nonterminal and α being a string of terminals and/or nonterminals.

    And a Type 3 (regular) grammar:

    restricts its rules to a single nonterminal on the left-hand side and a right-hand side consisting of a single terminal, possibly followed by a single nonterminal.

    Your final grammar is:

    S → aC
    C → ad
    

    and that is not, strictly speaking, a Type 3 grammar because the production for C is not a "single terminal possibly followed by a single non-terminal"; rather, it is a single terminal followed by another single terminal. But that can trivially be rewritten as

    S → aC
    C → aD
    D → d
    

    in which all of the productions obey the Type 3 restriction. This simple transformation can be applied to any grammar which has productions consisting of one or more terminals possibly followed by a single non-terminal, and that is often used as a definition instead of the one in Wikipedia, since the end result is effectively the same.

    We can see that every Type 3 grammar is also a Type 2 grammar, since both of the right-hand sides allowed in the Type 3 grammar also conform to the description "a string of terminals and/or nonterminals". So it would not be wrong to say that your final grammar is Type 2, but since it is also Type 3, we would usually describe it as a Type 3 grammar.