[ragel-users] The meaning of Figure 2.1 in the manual

Peng Yu pengyu.ut at gmail.com
Fri Feb 22 01:35:55 UTC 2019


Hi,

I have a hard time to understand the exact meaning of Figure 2.1. I
understand the regex part.

But what `0 @{ res = 1; };` means.

How p and pe are used in `write init` and `write exec`?

char *p = argv[1];
char *pe = p + strlen(p) + 1;
%% write init;
%% write exec;

How to make the example on the right-hand-side of Figure 2.1 compiled? Thanks.

#include <string.h>
#include <stdio.h>
%%{
machine foo;
main :=
( 'foo' | 'bar' )
0 @{ res = 1; };
}%%
%% write data;
int main( int argc, char **argv )
{
int cs, res = 0;
if ( argc > 1 ) {
char *p = argv[1];
char *pe = p + strlen(p) + 1;
%% write init;
%% write exec;
}
printf("result = %i\n", res );
return 0;
}

-- 
Regards,
Peng



More information about the ragel-users mailing list