Results 1 to 6 of 6

Thread: Flex, Bison and qmake

  1. #1
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Flex, Bison and qmake

    Good afternoon,

    I've got the lex/yacc files for a parser written, and I know that they work, as I tested them separately, and I need to integrate these into a Qt4 project. that part's fine if I use qmake to generate the makefile, and then hack the makefile to make the damned thing compile properly.

    The problem I'm having is that qmake changes the filenames of the outputs, as well as the default prefixes for most of the lex/yacc stuff (such as the yylex() function, and yylval for example...), and I'd like it to not do that. I'd like to be able to go through qmake so that I don't have to hack at the makefile in order to make it work again.

    anyways, here's the project file I'm using for this parser, using a small quick and dirty test class I wrote.

    Qt Code:
    1. TEMPLATE = app
    2. TARGET +=
    3. DEPENDPATH += .
    4. INCLUDEPATH += .
    5.  
    6. # Input
    7. HEADERS += parse.h parser.y.h parseTest.h
    8. LEXSOURCES += parser.l
    9. YACCSOURCES += parser.y
    10. SOURCES += main.cpp parseTest.cpp
    11.  
    12. # Flex/bison specifics
    13.  
    14. QMAKE_LEX = flex
    15. QMAKE_YACC = bison
    16.  
    17. QMAKE_YACCFLAGS = -d -o y.tab.c
    18. QMAKE_YACC_HEADER =
    19. QMAKE_YACC_SOURCE =
    To copy to clipboard, switch view to plain text mode 

    This will generate a makefile that assumes you already know what kind of mangling qmake will do to your filenames (which I didn't, and I would prefer to not have to rewrite the code to make it work)

    Basically, these are the offending lines in the makefile that I don't want to be like that.

    Qt Code:
    1. parser_yacc.cpp: parser.y
    2. $(YACC) $(YACCFLAGS) -p parser -b parser parser.y
    3. -$(DEL_FILE) parser_yacc.cpp parser_yacc.h
    4. -$(MOVE) parser.tab.h parser_yacc.h
    5. -$(MOVE) parser.tab.c parser_yacc.cpp
    6.  
    7. parser_yacc.h: parser_yacc.cpp
    8.  
    9. parser_lex.cpp: parser.l
    10. $(LEX) $(LEXFLAGS) -Pparser parser.l
    11. -$(DEL_FILE) parser_lex.cpp
    12. -$(MOVE) lex.parser.c parser_lex.cpp
    To copy to clipboard, switch view to plain text mode 

    I do not want the -Pparser flag in the lex lines, nor the -p and -b tags in the yacc lines. I also want the makefile to contain the standard default lex.yy.c output for the lex output, and y.tab.h and y.tab.cpp as the yacc output, since I use C++ code for the parser, although the lexer contains only C code, and can probably run through g++ anyways.

    So to recap, I need a way to get qmake to not touch the filenames of the lex and yacc (or in this case, flex and bison) output, and to recognize that it hasn't touched the filenames in order to create the proper targets in the makefile for lex.yy.c (or lex.yy.cpp), y.tab.h, and y.tab.cpp

    I've spent the past day on this problem, scouring google, and trying as many different things as I could find. Hacking the makefile each time is an unacceptable solution, I need something that you could add to the project file itself, or at least something scriptable.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Flex, Bison and qmake

    I have a quick solution for you. Tell qmake to treat your lex and bison files with a "custom compiler". Take a look at our wiki (the "undocumented qmake" article) and qmake docs to see how to tell qmake about a custom compiler. Then you'll be able to simply tell qmake what exact commands to execute.

    A proper solution would be difficult to obtain as qmake assumes you might have more than one lex and yacc parser and modifies the symbols using yacc and lex interfaces to avoid name clashes, so if you don't use them the way qmake wants you to, it might be a bit difficult to adapt. Of course a semi-proper solution is to override some qmake variables which are responsible for all those modifications.

  3. The following user says thank you to wysota for this useful post:

    Hydragyrum (8th September 2006)

  4. #3
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Flex, Bison and qmake

    I had a feeling it'll be something like that...

    I've tried poking around a bit with it, but couldn't get it to work, It would appear in the makefile, but not under the "all" target...

    I'll try it some more tomorrow, as I am not currently at work now If there's any other documentation on that feature it would be great to know.

    Thanks.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Flex, Bison and qmake

    Try something like this (not tested):
    Qt Code:
    1. FLEXINPUTS = parser.l
    2. flex_c.output = lex.yy.c
    3. flex_c.input = FLEXINPUTS # it has to be done using a variable
    4. flex_c.commands = flex parser.l
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Mar 2006
    Location
    kingston.on.ca
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Flex, Bison and qmake

    for some reason, that wasn't working too well yesterday when I tried poking at it, but works now...

    For the interested, my full qmake project file, at least for this testing app is as follows

    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (2.00a) Thu Sep 7 15:54:07 2006
    3. ######################################################################
    4.  
    5. TEMPLATE = app
    6. TARGET +=
    7. DEPENDPATH += .
    8. INCLUDEPATH += .
    9.  
    10. # Input
    11. HEADERS += parse.h parser.y.h parseTest.h
    12. #LEXSOURCES += parser.l
    13. #YACCSOURCES += parser.y
    14. SOURCES += main.cpp parseTest.cpp
    15.  
    16. # Flex/bison specifics
    17.  
    18. #QMAKE_LEX = flex
    19. #QMAKE_YACC = bison
    20.  
    21. #QMAKE_YACCFLAGS = -d -o y.tab.c
    22. #QMAKE_YACC_HEADER =
    23. #QMAKE_YACC_SOURCE =
    24.  
    25. FLEXSOURCES = parser.l
    26. BISONSOURCES = parser.y
    27.  
    28. flex.commands = flex ${QMAKE_FILE_IN}
    29. flex.input = FLEXSOURCES
    30. flex.output = lex.yy.c
    31. flex.variable_out = SOURCES
    32. flex.depends = y.tab.h
    33. flex.name = flex
    34. QMAKE_EXTRA_COMPILERS += flex
    35.  
    36. bison.commands = bison -d -t -y ${QMAKE_FILE_IN} && mv y.tab.c y.tab.cpp
    37. bison.input = BISONSOURCES
    38. bison.output = y.tab.cpp
    39. bison.variable_out = SOURCES
    40. bison.name = bison
    41. QMAKE_EXTRA_COMPILERS += bison
    42.  
    43. bisonheader.commands = @true
    44. bisonheader.input = BISONSOURCES
    45. bisonheader.output = y.tab.h
    46. bisonheader.variable_out = HEADERS
    47. bisonheader.name = bison header
    48. bisonheader.depends = y.tab.cpp
    49. QMAKE_EXTRA_COMPILERS += bisonheader
    To copy to clipboard, switch view to plain text mode 

    I'll have to add windows and linux-specific definitions for the move command in the bison.commands, but apart from that it works fairly nicely.

    Still I'm not sure why it wasn't working yesterday..but's that's not important.

  7. #6
    Join Date
    May 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Flex, Bison and qmake

    Hi all,
    I know it is a very old thread but I used it to implement my bison/flex parser with Qt, at least I tried.

    I wrote a .pro file:

    Qt Code:
    1. # Flex/bison specifics
    2. FLEXSOURCES = VHDLParser.l
    3. BISONSOURCES = VHDLParser.y
    4.  
    5. #flex definition
    6. flex.name = Flex
    7. flex.input = FLEXSOURCES
    8. flex.output = ${QMAKE_FILE_BASE}.cpp
    9. flex.commands = flex -i -o${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
    10. #flex.CONFIG += target_predeps
    11. flex.variable_out = SOURCES
    12. QMAKE_EXTRA_COMPILERS += flex
    13.  
    14. #bison definition
    15. bison.name = Bison
    16. bison.input = BISONSOURCES
    17. bison.output = ${QMAKE_FILE_BASE}.cpp
    18. bison.commands = bison -d -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
    19. bison.clean = position.hh stack.hh location.hh VHDLParser.hpp
    20. bison.CONFIG += target_predeps
    21. bison.variable_out = SOURCES
    22. QMAKE_EXTRA_COMPILERS += bison
    23.  
    24. OTHER_FILES += \
    25. $$BISONSOURCES \
    26. $$FLEXSOURCES
    To copy to clipboard, switch view to plain text mode 

    But when I build my project, the flex compiler simply doesn't start. I can clearly see bison running in the console but not flex.
    Of course, when comes the time to link every object files, it doesn't work beceause yylex() is missing ...

    Please tell me what's wrong with this .pro.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.