2

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?

Sam Hobbs
  • 2,594
  • 3
  • 21
  • 32
  • Why did I get a down-vote? I can't improve future questions if I don't know what is wrong. – Sam Hobbs Sep 30 '16 at 22:09
  • When posting errors, you should always provide details (platform, program version, how the program was invoked, exact error message, etc.). This way people have a chance to help. Note that it wasn't me who downvoted. – skvadrik Oct 01 '16 at 09:11
  • Thank you, @skvadrik. I believe you that it was not you. Your explanation helps. I want to say that I suspect someone is down-voting everything I do just because it is me. I can't be sure if that is happening. – Sam Hobbs Oct 01 '16 at 18:50

1 Answers1

3

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

skvadrik
  • 586
  • 1
  • 3
  • 11
  • Yes that was it, except I can't find a built version of any version beyond 0.13.5. I was using the exe file that is provided for building PHP. I think they should add a note to the re2c samples page saying the sample requires 0.13.7 or higher. I used "[*]" and that works with the older version. – Sam Hobbs Sep 30 '16 at 22:58
  • 2
    If you are on Windows, the best way to to build re2c is to use Cygwin or Mingw: http://re2c.org/install/install.html#windowshttp://re2c.org/install/install.html#windows. MSVC builds are currently not supported. – skvadrik Oct 01 '16 at 08:59