[ragel-users] Re: Ragel for network protocols?

St├ęphane Bortzmeyer bortzme... at gmail.com
Thu Nov 9 15:17:16 UTC 2006


2006/11/8, Adrian Thurston <thurs... at cs.queensu.ca>:

> The mechanism for building machines with the state chart paradigm is hidden
> away in the language. You use the following operators
>
> label:  make labels
> ->      draw epsilon operations
> ,       join machines together without transitions
> ()      grouping comes in handy

OK, thanks, now, I have a state machine which is compiled. But, at
execution time, I always end in an invalid state. I wrote:

%%{
machine test;

      OPEN = 'O';
       CLOSE = 'C';

       main :=
               start:
               door_closed: (
                       OPEN -> door_open -> final
               ),
               door_open: (
                       CLOSE -> door_closed
               );
}%%

and then the ancillary code:

%% write data;

int main( int argc, char **argv )
{
        /* Mandatory Ragel variables, see the manual */
        int cs;
        char *p;
        char *pe;

        int res = 0;
        int i;
        %%write init;
        if ( argc > 1 ) {
           for (i=1; i<argc; i++)  {
              p = argv[i];
              pe = p + strlen(p) + 1;
              printf("Step %i: input %s, current state %i... ", i, p, cs);
              %%write exec;
              if (cs == test_error) {
                 printf("Error, invalid input\n");
                 break;
              }
              else {
                 printf("New state is %i\n", cs);
              }
           }
        }
        else {
	   printf("Usage: %s O C O C ...", argv[0]);
           return 1;
        }
        printf("result = %i\n", res );
        %%write eof;
        return 0;
}

But I always get:

% ragel test.rl | rlcodegen && gcc -o test test.c && ./test O C O
Step 1: input O, current state 0... Error, invalid input
result = 0



More information about the ragel-users mailing list