Undefined Reference To yywrap

后端 未结 5 1490
后悔当初
后悔当初 2020-12-07 22:10

I have a simple \"language\" that I\'m using Flex(Lexical Analyzer), it\'s like this:

/* Just like UNIX wc */
%{
int chars = 0;
int words = 0;
int lines = 0;         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 22:18

    I prefer to define my own yywrap(). I'm compiling with C++, but the point should be obvious. If someone calls the compiler with multiple source files, I store them in a list or array, and then yywrap() is called at the end of each file to give you a chance to continue with a new file.

    int yywrap() {
       // open next reference or source file and start scanning
       if((yyin = compiler->getNextFile()) != NULL) {
          line = 0; // reset line counter for next source file
          return 0;
       }
       return 1;
    }
    

提交回复
热议问题