NAME 

re2c - convert regular expressions to C/C++

SYNOPSIS 

re2c [-bdefghisuvVw1] [-o output] file

DESCRIPTION 

re2c is a preprocessor that generates C-based recognizers from regular expressions. The input to re2c consists of C/C++ source interleaved with comments of the form /*!re2c ... */ which contain scanner specifications. In the output these comments are replaced with code that, when executed, will find the next input token and then execute some user-supplied token-specific code.

For example, given the following code

char *scan(char *p)
{
/*!re2c
        re2c:define:YYCTYPE  = "unsigned char";
        re2c:define:YYCURSOR = p;
        re2c:yyfill:enable   = 0;
        re2c:yych:conversion = 1;
        re2c:indent:top      = 1;
        [0-9]+          {return p;}
        [ 00-377]     {return (char*)0;}
*/
}

re2c -is will generate

/* Generated by re2c on Sat Apr 16 11:40:58 1994 */
char *scan(char *p)
{
    {
        unsigned char yych;

        yych = (unsigned char)*p;
        if(yych <= '/') goto yy4;
        if(yych >= ':') goto yy4;
        ++p;
        yych = (unsigned char)*p;
        goto yy7;
yy3:
        {return p;}
yy4:
        ++p;
        yych = (unsigned char)*p;
        {return char*)0;}
yy6:
        ++p;
        yych = (unsigned char)*p;
yy7:
        if(yych <= '/') goto yy3;
        if(yych <= '9') goto yy6;
        goto yy3;
    }

}

You can place one /*!max:re2c */ comment that will output a "#define YYMAXFILL <n>" line that holds the maximum number of characters required to parse the input. That is the maximum value YYFILL(n) will receive. If -1 is in effect then YYMAXFILL can only be triggered once after the last /*!re2c */.

You can also use /*!ignore:re2c */ blocks that allows to document the scanner code and will not be part of the output.