Question: Write a program in C language that will take an input string from the user and use the finite state machine developed in the lecture
Write a program in C language that will take an input string from the user and use the finite state machine developed in the lecture to process the string to determine if all delimiters match correctly or not. The string delimiters are curly braces, parentheses, and square brackets. Only in C language. no CPP no C
There should be separate filescodes
cstack.c
cstack.h
util.c
util.h
fsmc
fsmh
main.c
boolean.h
Please help. My codes are nt working and I need an explanation esp for h files.
Preliminary Analysis for utilities such as isopen isclose and isbrother for delimiter check FSM
isopen
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
isclose
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
isbrother
Will receive a two characters passed to it and return boolean value TRUE or FALSE indicating whether or
not they are matching openclose 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 brothersPseudocode 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 Starting State:
Read next character in input string
If char is open delimiter, next state is
If char is close delimiter, next state is
If char is end of string, next state is
If character is anything else, next state is
State :
Push open delimiter on stack
Next state is
State :
If stack is not empty
If the character on top of stack is brother to current character
Next state is
Otherwise
Display error message
Return false
Otherwise
Display error message
Return false
Next state is
State :
If stack is empty
Return true
Otherwise
Display error message
Return false
State :
Next state is
Note: You are to write and make use of subprograms like isopen, isclose, and isbrother for this program
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
