0% found this document useful (0 votes)
20 views4 pages

CD Mini Project

The document describes a Python program that demonstrates how a Deterministic Finite Automaton (DFA) processes strings based on defined transitions and determines if strings are accepted or rejected. The program allows a user to define the DFA characteristics like states, start/final states, and transitions. It then displays the transition table and tests user-input strings, outputting whether each string is accepted or rejected by the DFA.

Uploaded by

G Meghana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

CD Mini Project

The document describes a Python program that demonstrates how a Deterministic Finite Automaton (DFA) processes strings based on defined transitions and determines if strings are accepted or rejected. The program allows a user to define the DFA characteristics like states, start/final states, and transitions. It then displays the transition table and tests user-input strings, outputting whether each string is accepted or rejected by the DFA.

Uploaded by

G Meghana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

MEENAKSHI SUNDARARAJAN ENGINEERING COLLEGE

#363, Arcot Road, Kodambakkam, Chennai – 600024, Tamil Nadu, India

Department: Computer Science & Engineering Register No.:311521104027

EX NO:

CONVERSION OF ˈEPSILON - NFA TO DFA


DATE:

AIM:
The aim of this program is to demonstrate how a Deterministic Finite Automaton (DFA) processes
strings based on given transitions and determines whether each string is accepted or rejected
according to the specified DFA.

OBJECTIVE:

1. Take user input to define the DFA, including the number of states, start state, final states, and
transition rules.
2. Display the transition table of the DFA.
3. Allow the user to input strings to be tested against the DFA.
4. Determine if each string is accepted or rejected by the DFA based on the specified transitions.

SOFTWARE REQUIRED:

Anaconda, Jupyter Notebook

DESCRIPTION:

The provided Python program demonstrates the functionality of a Deterministic Finite Automaton
(DFA), an essential concept in automata theory and formal language theory. The DFA is a
mathematical model that represents a simplified computer or processor, capable of recognizing a
specific set of strings over an alphabet. The program allows users to define the DFA's characteristics,
including the number of states, start state, final states, and transition rules.

To start, the user inputs the number of states in the DFA, the start state, and the set of final states.
Subsequently, the program prompts the user to define the transition rules for each state and input
symbol (0 or 1). The transition rules are represented in a transition table, specifying the next state for
each combination of current state and input symbol.

After setting up the DFA, the program showcases the transition table, displaying the transitions for
each state based on input symbols. Users can then input a string to be evaluated by the DFA. The
program traces the string's path through the DFA according to the defined transition rules, displaying

Page No.:
MEENAKSHI SUNDARARAJAN ENGINEERING COLLEGE

#363, Arcot Road, Kodambakkam, Chennai – 600024, Tamil Nadu, India

Department: Computer Science & Engineering Register No.:311521104027

the sequence of states it passes through. Finally, the program indicates whether the string is accepted
or rejected based on whether the final state is one of the defined accept states.

In essence, this program provides a hands-on demonstration of how a DFA processes strings, making
it a valuable tool for understanding DFA behavior and its significance in various computational
applications, including lexical analysis in compilers, network protocol design, and natural language
processing.

PROGRAM:

def get_input():

st = int(input("Enter the number of states: "))

start_state = int(input("Enter the start state: "))

final_states = list(map(int, input("Enter the final states (space-separated): ").split()))

dfa = [[0, 0] for _ in range(st)]

for i in range(st):

print(f"Enter transitions for state {i} (0 and 1): ", end="")

dfa[i] = list(map(int, input().split()))

return st, start_state, final_states, dfa

def print_transition_table(states, dfa):

print("STATE\t0\t1")

for i in range(states):

print(f"{i}\t{dfa[i][0]}\t{dfa[i][1]}")

Page No.:
MEENAKSHI SUNDARARAJAN ENGINEERING COLLEGE

#363, Arcot Road, Kodambakkam, Chennai – 600024, Tamil Nadu, India

Department: Computer Science & Engineering Register No.:311521104027

def is_string_accepted(string, start_state, final_states, dfa):

curr_state = start_state

print(f"String takes the following path --> {curr_state}", end="")

for digit in string:

curr_state = dfa[curr_state][int(digit)]

print(f"-{curr_state}", end="")

print(f"\nFinal state - {curr_state}")

return curr_state in final_states

def main():

states, start_state, final_states, dfa = get_input()

print("Solving according to DFA")

print_transition_table(states, dfa)

num_strings = int(input("Enter the number of strings to test: "))

for i in range(num_strings):

string = input(f"Enter string {i + 1}: ")

if is_string_accepted(string, start_state, final_states, dfa):

print("String Accepted")

else:

print("String Rejected")

Page No.:
MEENAKSHI SUNDARARAJAN ENGINEERING COLLEGE

#363, Arcot Road, Kodambakkam, Chennai – 600024, Tamil Nadu, India

Department: Computer Science & Engineering Register No.:311521104027

if __name__ == "__main__":

main()

OUTPUT:

RESULT:

The program to convert epsilon-NFA to DFA is successfully executed.

Page No.:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy