c++syntax-errorre2c

Syntax error from default rule "*"


When compiling (processing using re2c) the sample Recognizing integers: the sentinel method I get:

re2c : error : line 16, column 9: syntax error

It seems to be complaining about the "*". The following is my 01_recognizing_integers.re file (except without the comment on line 16):

#include <stdio.h>

static const char *lex(const char *YYCURSOR)
{
    const char *YYMARKER;
    /*!re2c
        re2c:define:YYCTYPE = char;
        re2c:yyfill:enable = 0;

        end = "\x00";
        bin = '0b' [01]+;
        oct = "0" [0-7]*;
        dec = [1-9][0-9]*;
        hex = '0x' [0-9a-fA-F]+;

        *       { return "err"; }       // line 16
        bin end { return "bin"; }
        oct end { return "oct"; }
        dec end { return "dec"; }
        hex end { return "hex"; }
    */
}

int main(int argc, char **argv)
{
    for (int i = 1; i < argc; ++i) {
        printf ("%s: %s\n", lex(argv[i]), argv[i]);
    }
    return 0;
}

If I remove that line with the asterisk then there is no error, the output is generated and the compiler compiles it and the program works (except I removed the error samples from the tests). Is the sample wrong? How do I fix it to work as intended?


Solution

  • What re2c version do you have?

    You need re2c-0.13.7 or higher (re2c-0.13.7.5 is the stable release in 0.13.x series).

    re2c-0.16 is the latest stable release.

    For older re2c versions, use [^] instead of * and read this: http://re2c.org/manual/warnings/undefined_control_flow/wundefined_control_flow.html#difference-between-and