below are practicals and their solutions of Theory of Computation for Mumbai University SYBsc Computer Science updated complete list.
Aim : Write a program for tokenization of given input
Code:
my_text = “”” India is a land of various cultures and heritage. It is the seventh-largest country by area and the second-most populous country globally. The peacock is India’s national bird, and the Bengal tiger is the country’s national animal. The national song is named Vande Matram and is written by Bankimchandra Chatterji. “””
print(my_text.split(‘. ‘))
Output :
Aim : Write a program for generating regular expressions for regular grammer.
Code :
import re
s = ‘A computer science book for students’
match = re.search(r’students’, s)
print(‘Start Index:’, match.start())
print(‘End Index:’, match.end())
Output :
Aim : Write a program for generating derivation sequence / language for the given sequence of productions.
Aim : Design a Program for creating machine that accepts the string always ending with 101.
Code :
arr = [1, 1, 1, 4, 1, 1, 1, 5, 5, 5, 3, 8 ,2 ,3 ,4]
size = len(arr)
temp = 0
print(“The concecutive ones are: \n”);
for i in range(size – 2):
if arr[i] == 1 and arr[i] == arr[i + 1] and arr[i + 1] == arr[i + 2]:
temp = temp +arr[i]
print(“Number of 1’s are”,temp);
Output :
Aim : Design a program for accepting decimal number divisible by 2.
Code :
def stateq0(n):
if (len(n)==0):
print(“Divisible by 2”)
else:
if(n[0]==’0′):
stateq0(n[1:])
elif (n[0]==’1′):
stateq1(n[1:])
def stateq1(n):
if (len(n)==0):
print(“Not divisible by 2”)
else:
if(n[0]==’0′):
stateq0(n[1:])
elif (n[0]==’1′):
stateq1(n[1:])
n=int(input())
n = bin(n).replace(“0b”, “”)
stateq0(n)
Output :
Aim : Design a program for creating a machine which accepts string having equal no. of 1’s and 0’s.
Code :
Output :