Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Finite State Automata and Regular Expressions This project explores the imp

ID: 3839046 • Letter: J

Question

Java

Finite State Automata and Regular Expressions

This project explores the implementation of finite state machines and has two parts.

1) Write a program that starts by asking the user to describe a finite state automaton. You then display a regular expression describing the strings accepted by this FSA.

2) Write a program that takes a regular expression as an input and describes the FSA associated with the expression.

For both parts, allow the user to enter a bit string and have your program determine whether it is accepted or rejected by their FSA or regular expression.

v newgameproject v new gameproject main opp glut CPP h glut h brickGame.cpp h brick Game h Products #include brickGame.h #include glut. h" aincludeestdlib.hs- Created a method called BrickBreakingGame void BrickBreakingGame for (int m 0, 4, s 410 m

Explanation / Answer

#include #include #include using namespace std; typedef int fsm_state; typedef char fsm_input; bool is_final_state(fsm_state state) { return (state == 3) ? true : false; } fsm_state get_start_state(void) { return 0; } fsm_state move(fsm_state state, fsm_input input) { // our alphabet includes only 'a' and 'b' if (input != 'a' && input != 'b') assert(0); switch (state) { case 0: if (input == 'a') { return 1; } else if (input == 'b') { return 0; } break; case 1: if (input == 'a') { return 1; } else if (input == 'b') { return 2; } break; case 2: if (input == 'a') { return 1; } else if (input == 'b') { return 3; } break; case 3: if (input == 'a') { return 1; } else if (input == 'b') { return 0; } break; default: assert(0); } } bool recognize(string str) { if (str == "") return false; fsm_state state = get_start_state(); string::const_iterator i = str.begin(); fsm_input input = *i; while (i != str.end()) { state = move(state, *i); ++i; } if (is_final_state(state)) return true; else return false; } // simple driver for testing int main(int argc, char** argv) { recognize(argv[1]) ? cout < 1 : cout < 0; return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote