Lab Assignment-I
Lab Assignment-I
𝑟2 𝑟3
b. 𝑟2 | 𝑟3
𝑟2
ε
ε
ε
ε 𝑟3
ε
Programming Assignment –II
Given a NFA for a regular expression created using Thomson’s construction rules defined in
programming assignment-I create a Deterministic automata DFA. The DFA will match all the
words of grammar generated by the regular expression.
a
b a
a b
0 1 2
Implementation of DFA
𝑠 ç 𝑠7 \\ { 𝑠𝑡𝑎𝑟𝑡 𝑓𝑟𝑜𝑚 𝑡ℎ𝑒 𝑖𝑛𝑖𝑡𝑖𝑎𝑙 𝑠𝑡𝑎𝑡𝑒 }
𝑐 ç 𝑛𝑒𝑥𝑡𝑐ℎ𝑎𝑟 \\{ 𝑔𝑒𝑡 𝑡ℎ𝑒 𝑛𝑒𝑥𝑡 𝑐ℎ𝑎𝑟𝑎𝑐𝑡𝑒𝑟 𝑓𝑟𝑜𝑚 𝑡ℎ𝑒 𝑖𝑛𝑝𝑢𝑡 𝑠𝑡𝑟𝑖𝑛𝑔 }
𝑤ℎ𝑖𝑙𝑒 (𝑐 ! = 𝑒𝑜𝑠)𝑑𝑜 \\{ 𝑑𝑜 𝑢𝑛𝑡𝑖𝑙 𝑡ℎ𝑒 𝑒𝑛𝑑 𝑜𝑓 𝑡ℎ𝑒 𝑠𝑡𝑟𝑖𝑛𝑔 }
𝑏𝑒𝑔𝑖𝑛
𝑠 ç 𝑚𝑜𝑣𝑒(𝑠, 𝑐) \\{ 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 }
𝑐 ç 𝑛𝑒𝑥𝑡𝑐ℎ𝑎𝑟
𝑒𝑛𝑑
𝑖𝑓 (𝑠 𝑖𝑛 𝐹)𝑡ℎ𝑒𝑛 \\{ 𝑖𝑓 𝑠 𝑖𝑠 𝑎𝑛 𝑎𝑐𝑐𝑒𝑝𝑡𝑖𝑛𝑔 𝑠𝑡𝑎𝑡𝑒 }
𝑟𝑒𝑡𝑢𝑟𝑛 “𝑦𝑒𝑠”
𝑒𝑙𝑠𝑒
𝑟𝑒𝑡𝑢𝑟𝑛 “𝑛𝑜”
Conversion of NFA to DFA
To convert and Non-deterministic Finite automata (NFA) into a Deterministic Finite Automata
(DFA)
The ∈-closure of a state is the set of all states, including S itself, that you can get to via ∈-
transitions. The ∈-closure of state 𝑆 is denoted: L𝑆
𝑝𝑢𝑠ℎ 𝑎𝑙𝑙 𝑠𝑡𝑎𝑡𝑒𝑠 𝑜𝑓 𝑇 𝑜𝑛𝑡𝑜 𝑠𝑡𝑎𝑐𝑘
𝑖𝑛𝑖𝑡𝑖𝑎𝑙𝑖𝑧𝑒 𝜖 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒(𝑇) 𝑡𝑜 𝑇
𝒘𝒉𝒊𝒍𝒆 (𝑠𝑡𝑎𝑐𝑘 𝑖𝑠 𝑛𝑜𝑡 𝑒𝑚𝑝𝑡𝑦) 𝑑𝑜
𝑏𝑒𝑔𝑖𝑛
𝑝𝑜𝑝 𝑡, 𝑡ℎ𝑒 𝑡𝑜𝑝 𝑒𝑙𝑒𝑚𝑒𝑛𝑡, 𝑜𝑓𝑓 𝑠𝑡𝑎𝑐𝑘;
𝒇𝒐𝒓 (𝑒𝑎𝑐ℎ 𝑠𝑡𝑎𝑡𝑒 𝑢 𝑤𝑖𝑡ℎ 𝑎𝑛 𝑒𝑑𝑔𝑒 𝑓𝑟𝑜𝑚 𝑡 𝑡𝑜 𝑢 𝑙𝑎𝑏𝑒𝑙𝑙𝑒𝑑 𝜖 𝑑𝑜
𝑏𝑒𝑔𝑖𝑛
𝒊𝒇 (𝑢 𝑖𝑠 𝑛𝑜𝑡 𝑖𝑛 𝜖 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒(𝑇)) 𝑑𝑜
𝑏𝑒𝑔𝑖𝑛
𝑎𝑑𝑑 𝑢 𝑡𝑜 𝜖 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒(𝑇)
𝑝𝑢𝑠ℎ 𝑢 𝑜𝑛𝑡𝑜 𝑠𝑡𝑎𝑐𝑘
𝑒𝑛𝑑
𝑒𝑛𝑑
𝑒𝑛𝑑
Example:
This constructs a dfa that has no epsilon-transitions and a single accepting state.