Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simulating a DFA: Application 1 - Strings containing cbaa, bab, or cca Write a program that recognizes strings over the alphabet {a,b,c} that contain any

Simulating a DFA: Application 1 - Strings containing cbaa, bab, or cca

Write a program that recognizes strings over the alphabet {a,b,c} that contain any of the substrings cbaa, bab, or cca. Your program is supposed to act like a finite state machine, so it is restricted to the following rules:

Read only one character at a time. Do not store the characters in an array or a string variable. Your program must keep track of what it has seen (and what it still needs to see in order to have a good substring) as it goes along because it can only read a character once. It will do this by changing states.

As soon as your program detects the newline character that marks the end of one string, it must write either "Accept" or "Reject" to the screen (depending on whether the string just read is or is not in the language), then skip a line, then print "Your string> " and start processing the next string.

If the user types a string that contains any character other than a or b or c, your program should answer "Reject" to that string.

If the user presses "Enter" without typing any letters, that entry is to be considered the empty string and so your program should respond with "Reject".

Your program will continue to process strings until the user breaks into the program by forcibly ending the infinite loop (typing "Ctrl c" on student2), so your outermost loop can be an infinite loop.

Please use the template below and edit the code. Thanks!

image text in transcribedimage text in transcribed

A Java Program Simulating a Finite State Acceptor Example of a Java program simulating a finite state machine: 1. Label the states in your machine, starting at 0 . 2. Make a transition table for your machine. Add an extra trap state that will handle an input character that is not in your alphabet. Make a column in your table for characters outside the alphabet. (Below the trap state is state 5, and column 2 is for characters other than a, b). 3. See if you understand the program below. The method run() is simulating the machine. You can use the same program skeleton shown below for any finite state acceptor. What would need to change for a different machine? 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

Students also viewed these Databases questions

Question

1. Why do you think that most people treat email so casually?

Answered: 1 week ago