Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that will take an input string from the user and use the finite state machine developed in lecture to process the string

Write a program that will take an input string from the user and use the finite state machine developed in lecture to process the string to determine if all delimiters match correctly or not. The string delimiters are curly braces, parentheses, and square brackets. You must follow the preliminary analysis directly.

Lang: C (NOT C++)

PLEASE FOLLOW THE PAGES ADDED. (and keep it in one code. )

image text in transcribed

image text in transcribed

Pseudocode for main: - Get a string from user - If string has correctly matched delimiters print "All matched correctly" Pseudocode for FSM: Note: This is to be implemented as a subprogram that returns a boolean value of true or false indicating whether or not all delimiters matched correctly. State 0 (Starting State): - Read next character in input string - If char is open delimiter, next state is 1 - If char is close delimiter, next state is 2 - If char is end of string, next state is 3 - If character is anything else, next state is 4 State 1: - Push open delimiter on stack - Next state is 0 State 2: - If stack is not empty - If the character on top of stack is brother to current character - Next state is 0 Otherwise - Display error message - Return false - Otherwise Display error message Return false - Next state is 0 State 3: - If stack is empty - Return true - Otherwise Display error message Return false State 4: - Next state is 0 Note: You are to write and make use of subprograms like is_open, is_close, and is_brother for this program is_open() Will receive a single character passed to it and return boolean value TRUE or FALSE indicating whether or not it is an open delimiter. If character is open parenthesis, open curly brace, or open square bracket Return boolean value TRUE to indicate character is open delimiter Otherwise Return boolean value FALSE to indicate character is not an open delimiter is_close() Will receive a single character passed to it and return boolean value TRUE or FALSE indicating whether or not it is a close delimiter. If character is close parenthesis, close curly brace, or close square bracket Return boolean value TRUE to indicate character is close delimiter Otherwise Return boolean value FALSE to indicate character is not close delimiter is_brother() Will receive a two characters passed to it and return boolean value TRUE or FALSE indicating whether or not they are matching open/close pair. Note: First character will be open delimiter and second character will be close delimiter If open delimiter is left parenthesis and close is right parenthesis OR open delimiter is a left curly brace and close delimiter is right curly brace OR open delimiter is a left square bracket and close delimiter is right square bracket Return boolean value TRUE to indicate they are a matching pair (ie brothers) Otherwise Return boolean value FALSE to indicate they are not a matching pair (ie not brothers)

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

4. Describe cultural differences that influence perception

Answered: 1 week ago