Need help with FSMs...


 
Thread Tools Search this Thread
Top Forums Programming Need help with FSMs...
# 1  
Old 11-06-2006
Need help with FSMs...

hii..
I need to implement a pure virtual FSM program design which copies stdin to stdout, converting any C trigraphs found to their single character form (e.g. converting trigraph ??= to #) including those in the comments.
implement a pure virtual FSM program design. See the class notes for more information regarding FSM design.
i dint understand how do i give the states..that is how to check for two continous '?' symbpls and the the other special characters...

My program..(itz not complete one..):


#include <stdio.h>
#define START '?' /* states */
#define SAW_1 '?'
#define SAW_2 '('
#define SAW_3 ')'
int main( void)
{
int state, next, c, out;
setbuf( stdout, 0); /* make stdout unbuffered */
next = START; /* set initial state */
while( 1)
{
/* get next input */
c = getchar(); if( c < 0) break; if( c == '\n') putchar(c);
if( c != '?' && c != '('&& c != ')') continue; /* skip bad inputs */
state = next; /* get next state */
out = '0'; /* set default output */
switch( state)
{
case START:
if( c == '?') next = SAW_1;
else next = START;
break;
case SAW_1:
if( c == '?') next = SAW_2;
else next = START;
break;
case SAW_2:
if( c == '(')
{
out='[';
printf( "%c", out);
next =START;
}
else
next=SAW_3;
break;
case SAW_3:
if( c == ')')
{
out = ']';
printf( "%c", out);
next = START;
}
else
next = START;
break;
}
}
return 0;
}
# 2  
Old 11-06-2006
Please take note of the forum rules:

Quote:
(6) Do not post classroom or homework problems.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question