CD Mini Project
CD Mini Project
EX NO:
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:
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
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():
for i in range(st):
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
curr_state = start_state
curr_state = dfa[curr_state][int(digit)]
print(f"-{curr_state}", end="")
def main():
print_transition_table(states, dfa)
for i in range(num_strings):
print("String Accepted")
else:
print("String Rejected")
Page No.:
MEENAKSHI SUNDARARAJAN ENGINEERING COLLEGE
if __name__ == "__main__":
main()
OUTPUT:
RESULT:
Page No.: