Toa Ass3 Final
Toa Ass3 Final
Toa Ass3 Final
S → aSb
S→ε
In this example, the grammar allows the production of strings where the number of 'a's is
the same as the number of 'b's.
2. Type-1: Context-Sensitive Grammar (Context-Sensitive Languages):
Type-1 grammars generate languages known as context-sensitive languages. In these
grammars, the rules have specific constraints on the form of production rules, where the
left-hand side can be expanded or rewritten as the right-hand side while considering the
surrounding context. The context-sensitive languages can be recognized by linear-
bounded automata.
Example:
αAβ → αγβ
In this example, the production rule allows the non-terminal symbol A to be replaced by γ
only when it appears in the context of α and β.
3. Type-2: Context-Free Grammar (Context-Free Languages):
Type-2 grammars generate languages known as context-free languages. In context-free
grammars, the left-hand side of the production rules consists of a single non-terminal
symbol that can be replaced by a string of symbols, regardless of the context. Context-
free languages can be recognized by pushdown automata.
Example:
S → aSb
S→ε
This grammar generates strings where any number of 'a's can be followed by the same
number of 'b's.
4. Type-3: Regular Grammar (Regular Languages):
Type-3 grammars generate languages known as regular languages. Regular grammars
have the simplest form, where the production rules are limited to a single non-terminal
symbol on the left-hand side and a regular expression on the right-hand side. Regular
languages can be recognized by finite-state automata.
Example:
S → aS
S→b
This grammar generates strings consisting of any number of 'a's followed by a single 'b'.
Each level in the Chomsky hierarchy represents a different class of languages with varying levels of
complexity and generative power. As we move from Type-3 to Type-0, the grammars become more
expressive but also more complex to work with.