#125 Backslashes not escaped in #line from %top{}


I'm using the msys-flex package, build 2.5.35-2 according to mingw-get, running from msys-bash on a windows XPsp3 Pro/en-us system.

I have a flex file that starts like this:

%option 8bit
%option C++
%option full
%option nodefault
/*%option never-interactive*/
%option warn
%option yylineno

%top {
#include "vvm/close/compiler/close_parser.hpp"

#define yyerror( msg ) LexerError( msg )
#define IGNORE() /* IGNORE */
#define SAVE_TEXT() do { yylval.string = new std::string( YYText(), YYLeng() ); } while (0)
#define TOKEN(t) ( yylval.token = t )


If I grep for the input file name (close_lexer.flex) on the generated .cpp file, I get:

$ grep close_lexer.flex close_lexer.cpp
#line 10 "d:\devel\Vavoom\Vavoom\source\vvm\close\compiler\close_lexer.flex"
#line 1 "d:\\devel\\Vavoom\\Vavoom\\source\\vvm\\close\\compiler\\close_lexer.flex"
#line 32 "d:\\devel\\Vavoom\\Vavoom\\source\\vvm\\close\\compiler\\close_lexer.flex"

Notice the #line 10 directive contains un-escaped backslashes. This is the only place in the file where the backslashes are not escaped (there are many more #line directives).

I suspect that there may be some special treatment given to %top {} blocks, and the bug lies in that code.

This is non-trivial only to the extent that compilers (particularly g++) complain about the "unknown escape sequence"s that appear as a result of the unescaped backslashes. Nonetheless, it's a bunch of warning messages I would like to get rid of.


  • Tim Landscheidt

    Tim Landscheidt - 2012-02-05
    • assigned_to: nobody --> scfc_de
  • Tim Landscheidt

    Tim Landscheidt - 2012-02-08
    • status: open --> open-accepted
  • Tim Landscheidt

    Tim Landscheidt - 2012-02-08

    Thanks for the report. As a quick note for non-Windows systems, this can reproduced with a grammar called "bug\.l" (six characters with the fourth being a backslash):

    | %top {
    | }
    | %%

    that gets translated to:

    | [tim@passepartout ~/src/flex]$ fgrep '#line' lex.yy.c
    | #line 2 "bug\.l"
    ^- bug here
    | #line 6 "lex.yy.c"
    | #line 1 "bug\\.l"
    | #line 451 "lex.yy.c"
    | #line 3 "bug\\.l"
    | #line 635 "lex.yy.c"
    | #line 4 "bug\\.l"
    | #line 723 "lex.yy.c"
    | #line 4 "bug\\.l"
    | [tim@passepartout ~/src/flex]$

  • Will Estes

    Will Estes - 2012-03-23

    This has been fixed in the flex codebase and will be included in the next flex release.

  • Will Estes

    Will Estes - 2012-03-23
    • status: open-accepted --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks