(Solved) : Mealy Machine Exercises Specify Design Implement General Representation Mealy Machine Set Q37169380 . . .
Mealy Machine Exercises
-
Specify, design, and implement a general representation for aMealy Machine as a set of Scala definitions implementing anabstract data type. It should hide the representation of themachine behind an abstract interface and should have, at least, thefollowing public operations.
-
Constructor MealyMachine(s) creates a new machine with initial(and current) state s and no transitions.
-
Mutator method addState(s) adds a new state s to this machineand returns an Either wrapping the modified machine or an errormessage.
-
Mutator method addTransition(s1,in,out,s2) adds a new transitionto this machine and returns an Either wrapping the modified machineor an error message. From state s1 with input in, the modifiedmachine outputs out and transitions to state s2.
-
Mutator method addResets adds all reset transitions to thismachine and returns the modified machine. This operation makes thetransition function a total function by adding any missingtransitions from a state back to the initial state.
-
Mutator method setCurrent(s) sets the current state of thismachine to s and returns an Either wrapping the modified machine oran error message.
-
Accessor method getCurrent returns the current state of thismachine.
-
Accessor method getStates returns a list of the elements of thestate set of this machine.
-
Accessor method getInputs returns a list of the input set ofthis machine.
-
Accessor method getOutputs returns a list of the output set ofthis machine.
-
Accessor method getTransitions returns a list of the transitionset of this machine. Tuple (s1,in,out,s2) occurs in the returnedlist if and only if, from state s1 with input in, the machineoutputs out and moves to state s2.
-
Accessor method getTransitionsFrom(s) returns an Either wrappinga list of the set of transitions enabled from state s of thismachine or an error message.
Note: It is possible to use a Labelled Digraph ADT module in theimplementation of the Mealy Machine. A state is a vertex of thegraph, transition is an edge of the graph, and an (in,out) is alabel for an edge.
-
-
Given the above implementation for a Mealy Machine ADT, designand implement a separate Scala module that simulates the executionof a Mealy Machine. It should have, at least, the following publicoperations.
-
Mutator move(m,in) moves machine m from the current state giveninput in and returns an Either wrapping a tuple (mm,out) or anerror message. The tuple gives the modified machine mm and theoutput out.
-
Mutator method simulate(m,ins) simulates execution of machine mfrom its current state through a sequence of moves for the inputsin list ins and returns an Either wrapping a tuple (mm,outs) or anerror message. The tuple gives the modified machine mm after thesequence of moves and the output list outs.
-
Expert Answer
Answer to Mealy Machine Exercises Specify, design, and implement a general representation for a Mealy Machine as a set of Scala de…
OR