two state machines
    mitchell 
    mforal.n... at gmail.com
       
    Sat Jun  7 05:39:45 UTC 2008
    
    
  
Hi,
Untested, but it's an idea I had:
> #include <string.h>
> #include <stdio.h>
> %%{
>         machine FSM;
            char *substring_start, *substring_end;
>
>         FMS1 := ????          <- this parse a part of the string
            FMS1 := 'bar' @{ [do stuff] };
>         main := ????           <- this verify the string to match a pattern
            main := 'foo' >{ substring_start = p; }
                                 @{ substring_end = p; fgoto FMS1; };
> and extract a substring to pass to FSM1
Substring is between substring_start and substring_end.
>
> }%%
>
> %% write data;
>
> void parse(char *buf)
> {
>         int cs;
>         char *p = buf;
>         char *pe = p + strlen(p) + 1;
>         char FN[16];
>
>         %% write init;
>         %% write exec;     <- main
>
>         %% write exec;     <- FSM1
You don't need the second exec; FSM1 is executed via fgoto if main
matches.
>
> }
>
> int main( int argc, char **argv )
> {
>         if ( argc > 1 ) {
>                 parse(argv[1]);
>         }
>         return 0;
>
> }
>
> otherwise what vcan I do and how? I need fgoto, fcall or other?
fgoto should do the job.
Take care,
    
    
More information about the ragel-users
mailing list