Partage
  • Partager sur Facebook
  • Partager sur Twitter

Compilation avec Lex | Yacc

    22 juin 2017 à 20:34:11

    Bonjour à tous,

    J'ai un petit soucis avec un programme que je suis en train de faire avec Lex et Yacc.

    J'essaye de faire passer mes propres objets à Lex et Yacc, mais en les conservant dans des pointeurs intelligent.

    Mais dans ces cas la, il n'aime pas trop (je n'ai pas essayé avec des raw pointers)

    Voici le message d'erreur:

    $ make
    [ 16%] [FLEX][scanner] Building scanner with flex 2.5.35
    [ 33%] [BISON][parser] Building parser with bison 3.0.2
    src/pry_parser.yy: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
    src/pry_parser.yy:47.5-8: warning: rule useless in parser due to conflicts [-Wother]
         {  }
         ^^^^
    Scanning dependencies of target prysme
    [ 50%] Building CXX object CMakeFiles/prysme.dir/src/main.cpp.o
    [ 66%] Building CXX object CMakeFiles/prysme.dir/src/pry_driver.cpp.o
    In file included from /usr/include/c++/6/memory:81:0,
                     from /home/necros/Prysme/src/pry_driver.hpp:4,
                     from /home/necros/Prysme/src/pry_driver.cpp:2:
    /usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘typename std::_MakeUniq<_Tp>::__single_object std::make_unique(_Args&& ...) [with _Tp = Pry::Scanner; _Args = {std::basic_ifstream<char, std::char_traits<char> >&}; typename std::_MakeUniq<_Tp>::__single_object = std::unique_ptr<Pry::Scanner>]’:
    /home/necros/Prysme/src/pry_driver.cpp:12:53:   required from here
    /usr/include/c++/6/bits/unique_ptr.h:791:30: error: no matching function for call to ‘Pry::Scanner::Scanner(std::basic_ifstream<char>&)’
         { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /home/necros/Prysme/src/pry_driver.hpp:6:0,
                     from /home/necros/Prysme/src/pry_driver.cpp:2:
    /home/necros/Prysme/src/pry_scanner.hpp:16:9: note: candidate: Pry::Scanner::Scanner(std::istream*)
             Scanner(std::istream *in) : yyFlexLexer(in) {}
             ^~~~~~~
    /home/necros/Prysme/src/pry_scanner.hpp:16:9: note:   no known conversion for argument 1 from ‘std::basic_ifstream<char>’ to ‘std::istream* {aka std::basic_istream<char>*}’
    /home/necros/Prysme/src/pry_scanner.hpp:12:11: note: candidate: constexpr Pry::Scanner::Scanner(const Pry::Scanner&)
         class Scanner : public yyFlexLexer {
               ^~~~~~~
    /home/necros/Prysme/src/pry_scanner.hpp:12:11: note:   no known conversion for argument 1 from ‘std::basic_ifstream<char>’ to ‘const Pry::Scanner&’
    /home/necros/Prysme/src/pry_scanner.hpp:12:11: note: candidate: constexpr Pry::Scanner::Scanner(Pry::Scanner&&)
    /home/necros/Prysme/src/pry_scanner.hpp:12:11: note:   no known conversion for argument 1 from ‘std::basic_ifstream<char>’ to ‘Pry::Scanner&&’
    In file included from /usr/include/c++/6/memory:81:0,
                     from /home/necros/Prysme/src/pry_driver.hpp:4,
                     from /home/necros/Prysme/src/pry_driver.cpp:2:
    /usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘typename std::_MakeUniq<_Tp>::__single_object std::make_unique(_Args&& ...) [with _Tp = Pry::Parser; _Args = {Pry::Driver&, Pry::Parser*}; typename std::_MakeUniq<_Tp>::__single_object = std::unique_ptr<Pry::Parser>]’:
    /home/necros/Prysme/src/pry_driver.cpp:13:63:   required from here
    /usr/include/c++/6/bits/unique_ptr.h:791:30: error: no matching function for call to ‘Pry::Parser::Parser(Pry::Driver&, Pry::Parser*)’
         { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /home/necros/Prysme/src/pry_scanner.hpp:8:0,
                     from /home/necros/Prysme/src/pry_driver.hpp:6,
                     from /home/necros/Prysme/src/pry_driver.cpp:2:
    /home/necros/Prysme/build/pry_parser.tab.hpp:448:5: note: candidate: Pry::Parser::Parser(const Pry::Parser&)
         Parser (const Parser&);
         ^~~~~~
    /home/necros/Prysme/build/pry_parser.tab.hpp:448:5: note:   candidate expects 1 argument, 2 provided
    /home/necros/Prysme/build/pry_parser.tab.hpp:417:5: note: candidate: Pry::Parser::Parser(Pry::Scanner&, Pry::Driver&)
         Parser (Scanner &scanner_yyarg, Driver  &driver_yyarg);
         ^~~~~~
    /home/necros/Prysme/build/pry_parser.tab.hpp:417:5: note:   no known conversion for argument 1 from ‘Pry::Driver’ to ‘Pry::Scanner&’
    make[2]: *** [CMakeFiles/prysme.dir/src/pry_driver.cpp.o] Error 1
    make[1]: *** [CMakeFiles/prysme.dir/all] Error 2
    make: *** [all] Error 2
    



    repo: https://github.com/Cruder/Prysme

    compilation:

    mkdir build
    cd build
    cmake ..
    make

    g++ version: gcc version 6.3.0 20170519 (Ubuntu/Linaro 6.3.0-18ubuntu2~14.04) 

    Ca fait assez longtemps que je n'ai pas fait de C++ et me suis en grande partie inspiré de https://github.com/jonathan-beard/simple_wc_example

    Merci de votre aide !

    Update

    -----------

    J'ai finalement retirer les smarts pointers pour le moment (je pense que c'est à Lex / Yacc de s'occuper de ceux ci)

    J'ai donc avancer sur la suite, mais je me retrouve avec un nouveau problème: 

    ➜ make
    [ 16%] Building CXX object CMakeFiles/prysme.dir/pry_lexer.yy.cpp.o
    src/pry_lexer.l:10:25: error: prototype for ‘int Pry::Scanner::yylex(const semantic_type*, Pry::Parser::location_type*)’ does not match any in class ‘Pry::Scanner’
    /home/necros/Prysme/build/pry_lexer.yy.cpp:669:1: note: in expansion of macro ‘YY_DECL’
     YY_DECL
     ^~~~~~~
    In file included from /home/necros/Prysme/build/pry_lexer.yy.cpp:392:0:
    /usr/include/FlexLexer.h:75:14: error: candidates are: virtual int FlexLexer::yylex()
      virtual int yylex() = 0;
                  ^~~~~
    /usr/include/FlexLexer.h:78:6: error:                 int FlexLexer::yylex(std::istream*, std::ostream*)
      int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 )
          ^~~~~
    In file included from src/pry_lexer.l:7:0:
    /home/necros/Prysme/./src/pry_scanner.hpp:19:21: error:                 virtual int Pry::Scanner::yylex(Pry::Parser::semantic_type*, Pry::Parser::location_type*)
             virtual int yylex(
                         ^~~~~
    make[2]: *** [CMakeFiles/prysme.dir/pry_lexer.yy.cpp.o] Error 1
    make[1]: *** [CMakeFiles/prysme.dir/all] Error 2
    make: *** [all] Error 2
    

    J'ai dans mon lex 

    #define YY_DECL int Pry::Scanner::yylex(const Pry::Parser::semantic_type* lval, Pry::Parser::location_type *loc)
    

    Et dans mon Pry::Scanner

    namespace Pry {
        class Scanner : public yyFlexLexer {
            using FlexLexer::yylex;
    
        public:
            Scanner(std::istream *in) : yyFlexLexer(in) {}
            virtual ~Scanner() {};
    
            virtual int yylex(
                Pry::Parser::semantic_type * const lval,
                Pry::Parser::location_type *location
            );
        private:
            /* yyval ptr */
            Pry::Parser::semantic_type *yylval = nullptr;
        };
    }

    Normalement il est sensé me faire une classe hérité, mais d'après les erreurs, ce n'est pas le cas.

    Une idée? 

    Merci :)

    -------------

    Update

    J'ai retirer le virtual sur 

    int yylex(const Parser::semantic_type* lval, Parser::location_type *loc);

    Et fait d'autres petits changements mineur, et me retrouve avec cette erreur:

    $ make 
    
    Scanning dependencies of target prysme
    [ 42%] Building CXX object CMakeFiles/prysme.dir/pry_parser.tab.cpp.o
    [ 42%] Building CXX object CMakeFiles/prysme.dir/src/pry_driver.cpp.o
    [ 42%] Building CXX object CMakeFiles/prysme.dir/src/main.cpp.o
    [ 57%] Building CXX object CMakeFiles/prysme.dir/pry_lexer.yy.cpp.o
    [ 71%] Linking CXX executable prysme
    CMakeFiles/prysme.dir/src/main.cpp.o: In function `main':
    /home/necros/Prysme/src/main.cpp:5: multiple definition of `main'
    /usr/lib/x86_64-linux-gnu/libfl_pic.a(libfl_pic_a-libmain.o):/build/buildd/flex-2.5.35/libmain.c:29: first defined here
    /usr/lib/x86_64-linux-gnu/libfl_pic.a(libfl_pic_a-libmain.o): In function `main':
    libmain.c:(.text.startup+0xb): undefined reference to `yylex'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o: In function `Pry::Scanner::Scanner(std::istream*, std::ostream*)':
    /home/necros/Prysme/src/pry_scanner.hpp:16: undefined reference to `yyFlexLexer::yyFlexLexer(std::istream*, std::ostream*)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x20): undefined reference to `yyFlexLexer::yy_switch_to_buffer(yy_buffer_state*)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x28): undefined reference to `yyFlexLexer::yy_create_buffer(std::istream*, int)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x30): undefined reference to `yyFlexLexer::yy_delete_buffer(yy_buffer_state*)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x38): undefined reference to `yyFlexLexer::yyrestart(std::istream*)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x40): undefined reference to `yyFlexLexer::yylex()'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x48): undefined reference to `yyFlexLexer::switch_streams(std::istream*, std::ostream*)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x50): undefined reference to `yyFlexLexer::yywrap()'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x58): undefined reference to `yyFlexLexer::LexerInput(char*, int)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x60): undefined reference to `yyFlexLexer::LexerOutput(char const*, int)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTVN3Pry7ScannerE[_ZTVN3Pry7ScannerE]+0x68): undefined reference to `yyFlexLexer::LexerError(char const*)'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o: In function `Pry::Scanner::~Scanner()':
    /home/necros/Prysme/src/pry_scanner.hpp:12: undefined reference to `yyFlexLexer::~yyFlexLexer()'
    CMakeFiles/prysme.dir/src/pry_driver.cpp.o:(.rodata._ZTIN3Pry7ScannerE[_ZTIN3Pry7ScannerE]+0x10): undefined reference to `typeinfo for yyFlexLexer'
    CMakeFiles/prysme.dir/pry_parser.tab.cpp.o:(.rodata._ZTVN3Pry6ParserE[_ZTVN3Pry6ParserE]+0x28): undefined reference to `Pry::Parser::error(Pry::location const&, std::string const&)'
    collect2: error: ld returned 1 exit status
    make[2]: *** [prysme] Error 1
    make[1]: *** [CMakeFiles/prysme.dir/all] Error 2
    make: *** [all] Error 2
    

    Je pense que c'est un problème de link, mais je ne vois pas du tout comment faire pour ajouter la librairie dans mon CMakeLists.txt.

    Pourtant j'ai bien 

    find_package(BISON REQUIRED)
    find_package(FLEX REQUIRED)
    





    -
    Edité par necros211 23 juin 2017 à 17:21:05

    • Partager sur Facebook
    • Partager sur Twitter

    Architecte logiciel - Software craftsmanship convaincu.

    Compilation avec Lex | Yacc

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown