Basic "Hello World" Example?

gautham angaut... at yahoo.com
Thu Jun 28 13:22:45 UTC 2007


Hi,

I too am new to Ragel. Following is a simple hello-world program I
wrote with Ragel.

<ragelcode file=first.rl>
#include<stdio.h>
#include<string.h>

%%{
    machine first;
    expr = "hello";
    expr2 = "world";
    expr3 = "start";
    main := expr @ {printf("+you said - hello+\n");} |
            expr2 @ {printf("+you said - world+\n");}|
            expr3 @ {printf("+you said - start+\n");};

}%%

%% write data;

void printarg(int argc, char **argv, int i);

int main(int argc, char **argv)
{
    int i;
    for(i=1; i<argc; i++)
        printarg(argc, argv, i);
}

void printarg(int argc, char **argv, int i)
{
    char *p = argv[i];
    char *pe = p + strlen(p) + 1;
    int cs;
    %%{
        write init;
        write exec;
    }%%
}

</ragelcode>

Hope it helps.

-gautham

On May 16, 4:59 am, Adrian Thurston <thurs... at cs.queensu.ca> wrote:
> The file atoi3.rl in the tests directory is a good one to look at. To
> find all ruby tests grep for 'LANG: ruby' in that directory. Note that
> some are generated and to make them requires txl to be installed.
>
> Cheers,
>  Adrian
>
> colin h wrote:
> > Greetings all!
>
> > I'm trying to learn more about Ragel, but having a difficult time
> > getting figuring out how to get something running.  I'm just wondering
> > if somone has a simple "Hello World!" type example using Ruby they can
> > send me.  It always helps when i have something working to then
> > break... 8)
>
> > Thanks in advance!
>
> > >
>
>
>  signature.asc
> 1KDownload



More information about the ragel-users mailing list