Group Assignment - Formal Language Theory
Group Assignment - Formal Language Theory
GROUP MEMBERS
S.No NAME ID SECTION YEAR DEPT.
QUESTIONS:
1. Briefly explain phrase structure grammar and the different types with example?
2. Briefly explain derivation of grammar and the different types with example?
3. Briefly explain deterministic and non-deterministic finite state automata with
example?
1. Briefly explain phrase structure grammar and the
different types with example?
phrase structure grammars are all those grammars that are based on the
constituency relation, as opposed to the dependency relation associated
with dependency grammars; hence, phrase structure grammars are also
known as constituency grammars
Type - 0 Grammar: -
o Example
AB → AbBc
A → bcA
B→b
Type - 2 Grammar
➢ Type-2 grammars generate context-free languages
The productions must be in the form A → γ
where A ∈ N (Non terminal)
and γ ∈ (T ∈ N)* (String of terminals and non-terminals).
✓ These languages generated by these grammars are be recognized by a non-
deterministic pushdown automaton.
o Example
S→Xa
X→a
X → aX
X → abc
X→ε
Type - 3 Grammar
➢ Type-3 grammars generate regular languages. Type-3 grammars must
have a single non-terminal on the left-hand side and a right-hand side
consisting of a single terminal or single terminal followed by a single non-
terminal.
The productions must be in the form X → a or X → aY
where X, Y ∈ N (Non terminal) and a ∈ T (Terminal)
✓ The rule S → ε is allowed if S does not appear on the right side of any rule.
o Example
X→ε
X → a | aY
Y→b
We have two options to decide which non-terminal to be placed with production rule.
1. Leftmost Derivation:
In the leftmost derivation, the input is scanned and replaced with the production rule
from left to right. So in leftmost derivation, we read the input string from left to right.
Example:
Production rules:
E=E+E
E=E-E
E=a|b
Input
a-b+a
E=E+E
E=E-E+E
E=a-E+E
E=a-b+E
E=a-b+a
2. Rightmost Derivation:
In rightmost derivation, the input is scanned and replaced with the production rule
from right to left. So in rightmost derivation, we read the input string from right to left.
o Example
Production rules:
E=E+E
E=E-E
E=a|b
Input
a-b+a
E=E-E
E=E-E+E
E=E-E+a
E=E-b+a
E=a-b+a
When we use the leftmost derivation or rightmost derivation, we may get the same
string. This type of derivation does not affect on getting of a string.
Example of Derivation:
Derive the string "abb" for leftmost derivation and rightmost derivation using a CFG
given by,
S → AB | ε
A → aB
B → Sb
Solution:
Leftmost derivation:
Rightmost derivation:
In a DFA, for a particular input character, the machine goes to one state only. A
transition function is defined on every state for every input symbol. Also in DFA null (or
ε) move is not allowed, i.e., DFA cannot change state without any input character.
For example, below DFA with Σ = {0, 1} accepts all strings ending with 0.
One important thing to note is, there can be many possible DFAs for a pattern. A DFA with
minimum number of states is generally preferred.
1. Null (or ε) move is allowed i.e., it can move forward without reading symbols.
2. Ability to transmit to any number of states for a particular input.
However, these above features don’t add any power to NFA. If we compare both in
terms of power, both are equivalent.
Due to above additional features, NFA has a different transition function, rest is
same as DFA.
δ: Transition Function
δ: Q X (Σ U ε ) --> 2 ^ Q.
As you can see in transition function is for any input including null (or ε), NFA can go to
any state number of states.
For example, below is a NFA for above problem