Question: Write in C programming Pseudocode for main: Get a string from user If string has correctly matched delimiters print All matched correctly Pseudocode for FSM
Write in C programming
Pseudocode for main:
Get a string from user
If string has correctly matched delimiters print All matched correctly
Pseudocode for FSM to Determine if Delimiters Match:
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
o If the character on top of stack is brother to current character
Next state is
o Otherwise
Display error message
Return false
Otherwise
o Display error message
o Return false
Next state is
State :
If stack is empty
o Return true
Otherwise
o Display error message
o Return false
State :
Next state is
Note: You are to write and make use of subprograms like isopen, isclose, and isbrother for this program
Starting State:
Increment input string's index value
If is operator, next state is
If is digit, next state is
If is space, next state is
If is end of string, next state is
If anything else, next state is
Found operator:
Pop nd number off stack
Pop st number off stack
Perform operation
Push result on stack
Next state is
Note: Watch popping empty stack and division by zero
Found digit:
Copy digit to temporary string
increment both the temporary and input string index values
If character in input string is a digit or decimal point
next state is
otherwise
next state
Found end of number:
append on temporary array
convert and assign to variable
push number on stack
reset temp index to
decrease input index by
next state is
Found space:
next state is
Found end of input string:
pop result
return answer
Note: Watch for leftovers on stack
Found garbage
display error message
exit from program
TFVEPDPEFGPS'UP&WBMVBUFOQVU
State :
Increment index string index
If current input is number, next state is
If current input is operator, next state is
If current input is left parenthesis, next state is
If current input is right parenthesis, next state is
If current input is end of string, next state is
If current input is garbage, next state is
State : found number
Copy current character to output string
Increment output string index
Increment input string index
While character in input string is digit or decimal point
o Copy character to output string
o Increment output string index
o Increment input string index
Put space in output string
Increment output string index
Decrement input string index
Next state is
State : found operator
While the stack is not empty and the character at top of stack is an operator and the precedence
of the operator that is current character in input string is less than or equal to that of the
operator on top of the stack
o Pop operator off top of stack and put in output string
o Increment output string index
o Put space in output string
o Increment output string index
If stack is not full, Push the operator that is current character in input string on stack
Otherwise, print error and exit
Next state is
State : found left parenthesis
If stack is not full, push left parenthesis found in current input character on stack
Otherwise, display error message and exit
Next state is
State : found right parenthesis
While stack is not empty and item at top of stack is not left parenthesis
o Pop operator off top of stack and put in output string
Pseudocode for FSM Implementing Reduced Version of DijkstraZeta s Shunting Yard Algorithm to Convert Algebraic Input to RPN
o Increment output string index
o Put space in output string
o Increment output string index
If stack is not empty, pop left parenthesis off stop of stack but do not put in output string
Otherwise, display error message mismatched parenthesis and exit
Next state is
State : End of input
While stack is not empty and character at top of stack is an operator
o Pop operator off stack and put in output string
o Increment output string index
o Put space in output string
o Increment output string index
If stack is not empty, display error message leftover parenthesis and exit
Otherwise, put end of string marker in output string and send output string to RPN Evaluator
Note: return rpnevaloutputstring;
State : garbage
Display error message and exit
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
