question archive you have implemented a generic FSA using files

you have implemented a generic FSA using files

Subject:Computer SciencePrice:9.82 Bought3

you have implemented a generic FSA using files. Now you are required to implement FSA for Identifier, Numbers, and string identification. Following are the RE for all these FSA. Number = (0-9)+ Identifier = ([a-z] + [A-Z] + _) ([a-z] + [A-Z] + [0-9] + _)* String =( " ) (ANY SYMBOL ^ " )* " Noted: Code require in python

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

for numbers: Using an finite-state automaton that checks if a binary number is divisible by three as an example

divisible = {    'S0': {0: 'S0', 1: 'S1', 'start': True , 'accept': True },    'S1': {0: 'S2', 1: 'S0', 'start': False, 'accept': False},    'S2': {0: 'S1', 1: 'S2', 'start': False, 'accept': False} }

Additionally, the matrix representation of the directed graph corresponding to the aforementioned FSA is as follows:  

div_matrix= [    [0, 1, ()],    [1, (), 0],    [(), 0, 1] ]

 

For string identifier

START_STATE = 1 transition = [] transition.append({}) 

# Creates an unused state 0

# Create a new state

transition.append({})

# Transition from state 0 on 'a' goes to state 1 transition[1]['a'] = 1

# Transition from state 0 on 'b' goes to state 0 transition[1]['b'] = 2 transition.append({}) transition[2]['a'] = 2 transition[2]['b'] = 1 state = START_STATE while True:    symbol = input("Enter next symbol: ")    print("Going from state", state, "to...")    state = transition[state][symbol]    print("    ... ", state)

 

Step-by-step explanation

Correct indentation will give correct results.