[ragel-users] Difference between generated C code using -G0 and -T0

Daniel Salzman daniel.salzman at nic.cz
Tue Jun 25 11:18:09 UTC 2013


At the beginning I would like to thank you for the great project Ragel.
It allows us (www.knot-dns.cz) to have realy fast parser for DNS zone files.

But I have recently noticed that there is a small bug in C code 
generation with G{0,1,2},
because there is different behaviour between G and T, F modes.

Meaningless and very pruned snippet of code which can demonstrate the 

== test.rl ==
#include <stdlib.h>
#include <stdio.h>

         machine zone_scanner;

         newline = '\n';
         comment = ';' . (^newline)*;
         wchar = [ \t\n;];

         sep = ( [ \t]
               | (comment? . newline) when { 0 }

         err_line := (^newline)* . newline @{ fgoto main; };

         action _text_char_error {
                 fhold; fgoto err_line;

         text = ^wchar . (alpha $!_text_char_error)+;

         main := "$INCLUDE" . sep . text . newline;

%% write data;

int main(int argc, char **argv)
         char buffer[4096];
         FILE* f;
         long numbytes;

         f = fopen(argv[1], "r");
         fseek(f, 0, SEEK_END);
         numbytes = ftell(f);
         fseek(f, 0, SEEK_SET);
         fread(buffer, 1, numbytes, f);

         char *p = buffer;
         char *pe = buffer + numbytes;
         char *eof = pe;
         int stack[16];
         int  cs = zone_scanner_start;
         int top;

         %% write exec;

         if (cs == zone_scanner_error) {
                 return -1;

         return 0;

== input.txt ==
$INCLUDE        ; Missing filename

ragel -T0 test.rl -o testT.c
gcc testT.c -o testT
./testT ./input.txt

ragel -G0 test.rl -o testG.c
gcc testG.c -o testG
./testG ./input.txt

Here you can see the state machines stop in different states.

Although this problem is marginal in our project, it would be nice if 
Ragel is absolute perfect :-)

Best regards,

ragel-users mailing list
ragel-users at complang.org

More information about the ragel-users mailing list