Question: In C, write a program to implement a finite state machine that detects a sequence of characters consisting using while()/switch() mechanism: #: while()/switch() mechanism consists

In C, write a program to implement a finite state machine that detects a sequence of characters consisting using while()/switch() mechanism:

In C, write a program to implement a finite state machine thatdetects a sequence of characters consisting using while()/switch() mechanism: #: while()/switch() mechanism

#: while()/switch() mechanism consists of this example:

chars;

count = 0;

while ( s = getchar() ! = EOF) {

switch (s) {

case A: {

if ( s = getchar() == 'D' ) {

count++; }

}

break;

}

case B: {

if ( s = getchar() == 'D' ) {

count++;

}

}

}switch

}while

Consider the finite state machine shown in Figure 1. This machine detects a sequence of characters that consist of zero or more 'A' characters followed by a 'B' and then a 'D', or the sequence 'ABD'. These two patterns can be expressed using the notation (A* B AC)D. The *** symbol specifies zero or more occurrences and the l' symbol specifies logical OR. For example, the following character patterns will be detected by the machine: BD ABD AABD AAABD ACD 0-0 0-0 0-0 Figure 1. Finite state machine for detecting pattern (A*B AC)D. Write a program to implement the machine using the while()-switch() mechanism # The circles represent machine states with the integer state value shown in the circle. To transition from one state to another where there is no character shown on an edge, perform an iteration of the while loop. If an edge has an associated letter, that character must be read using getchar() to transition states. Using the keyboard, enter several character patterns to verify detection. For example, typing the sequence CDAABCAAABDDACDAAC should report two pattern occurrences. Terminate the machine anytime EOF is read (i.e. ctrl-d). Consider the finite state machine shown in Figure 1. This machine detects a sequence of characters that consist of zero or more 'A' characters followed by a 'B' and then a 'D', or the sequence 'ABD'. These two patterns can be expressed using the notation (A* B AC)D. The *** symbol specifies zero or more occurrences and the l' symbol specifies logical OR. For example, the following character patterns will be detected by the machine: BD ABD AABD AAABD ACD 0-0 0-0 0-0 Figure 1. Finite state machine for detecting pattern (A*B AC)D. Write a program to implement the machine using the while()-switch() mechanism # The circles represent machine states with the integer state value shown in the circle. To transition from one state to another where there is no character shown on an edge, perform an iteration of the while loop. If an edge has an associated letter, that character must be read using getchar() to transition states. Using the keyboard, enter several character patterns to verify detection. For example, typing the sequence CDAABCAAABDDACDAAC should report two pattern occurrences. Terminate the machine anytime EOF is read (i.e. ctrl-d)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!