Question: Here is the code i have written so far, please finish it #include #include int i=-1; int nextstate=0; cstack top; init_cstack(&top); while(1) switch{ case 0:

Here is the code i have written so far, please finish it
#include
int i=-1; int nextstate=0; cstack top;
init_cstack(&top); while(1) switch{ case 0: i++; if (is_open(my_input[i])) nextstate= 1; else if (is_close(my_input[i])) nextstate= 2; else if (my_input[i] == '\0') nextstate= 3; else nextstate= 4; break; case 1: if(!is_cfull()){ cpush(&top, my_input[i]); nextstate= 0; } else{ printf("Error! Stack is full "); exit(0); } break; case 2: if (!is_cempty(top)){ if(is_brother(cpop(&top), my_input[i])){ nextstate= 0; } else{ printf("Error! Delimiter do not match "); return FALSE; } } else{ printf("No open delimiter to compare to "); return FALSE; } break; case 3: if (is_cempty(top)){ return TRUE; } else{ printf("Error! Extra open delimiter "); return FALSE; } break; case 4: nextstate =0; break; } }
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
