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

Adrian Thurston thurston at colm.net
Sat Feb 23 04:39:44 UTC 2019


Hi Peng, I recommend you read a bit more of the manual. You'll find all 
the answers there. Thanks!

On 2019-02-22 08:35, Peng Yu wrote:
> 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;
> }



More information about the ragel-users mailing list