Re: [Flex-help] Error changing yylex return.
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Will E. <wes...@gm...> - 2016-03-02 01:41:14
|
What version of flex are you running? On Tuesday, 1 March 2016, 10:13 pm -0300, "Fabricio S. Paranhos" <fab...@gm...> wrote: > I did some test to discovery what is going on. > I forward declared the new yylex inside my main file and everything went > OK. For some reason flex is not including the new declaration inside the > header file. > > Here some simple example in gist [1]. The file main2.c is main.c after > gcc preprocessor "gcc -E" > > The generated header file has the new yylex declaration: > >#ifndef yyHEADER_H > >#define yyHEADER_H 1 > >#define yyIN_HEADER 1 > > > >#line 2 "flex.l" > >#define YY_DECL double yylex(yyscan_t yyscanner) > > > > > > > >#line 11 "lex.yy.h" > > But after passing through compiler preprocessor it's removed, as you can > see in the main2.c file, and I have to forward declared the new > function. I don't know if this is the correct behavior or is a bug. > > [1] https://gist.github.com/anonymous/ec6d47fe8d7822f0e554 > > > On 02/29/2016 10:37 PM, Chris verBurg wrote: > > Hey Fabricio, > > > > To first order, your code all looks fine to me. It seems like your > > redeclaration is not making it into main.c -- I'd suggest maybe next > > looking at the generated flex.h and seeing what it's doing with YY_DECL and > > yylex. Maybe your %{..%} block has to be moved earlier or later in the > > first section? > > > > -Chris > > > > > > > > On Mon, Feb 29, 2016 at 2:06 PM, Fabricio S. Paranhos < > > fab...@gm...> wrote: > > > >> Hello, > >> > >> I'm trying to change the default return value (int) from yylex to a > >> structure. According to FLEX manual it's possible to change how yylex is > >> declared[1]: > >> > >> >This definition may be changed by defining the YY_DECL macro. For > >> >example, you could use: > >> > > >> > #define YY_DECL float lexscan( a, b ) float a, b; > >> > > >> > >> In my flex file I declared this way: > >> > >> >#define YY_DECL struct token yylex(yyscan_t yyscanner) > >> > >> But after using this macro and compiling the final main program I got > >> the following GCC error: > >> > >> >main.c: In function ‘main’: > >> >main.c:14:7: error: incompatible types when assigning to type ‘struct > >> >token’ from type ‘int’ > >> > lol = yylex(scanner); > >> > >> > >> Even after changing how yylex is declared the final result didn't > >> change. After some search on the web I found this[2] stack overflow > >> question, but I got the same error from GCC... > >> > >> Anybody can help? > >> > >> Here are some additional info: > >> OS: Debian 8 64bit > >> GCC: Debian 4.9.2-10 4.9.2 > >> Flex: 2.5.39 > >> > >> And here are my source files: > >> https://gist.github.com/anonymous/49beeae0d85b4a7f91d6 > >> > >> Thanks in advance. > >> > >> [1] > >> http://flex.sourceforge.net/manual/Generated-Scanner.html#Generated-Scanner > >> [2] > >> https://stackoverflow.com/questions/3796598/returning-non-ints-from-yylex > >> -- > >> Fabrício S. Paranhos > >> > >> > >> ------------------------------------------------------------------------------ > >> Site24x7 APM Insight: Get Deep Visibility into Application Performance > >> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > >> Monitor end-to-end web transactions and take corrective actions now > >> Troubleshoot faster and improve end-user experience. Signup Now! > >> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > >> -- > >> Flex-help mailing list > >> Fle...@li... > >> https://lists.sourceforge.net/lists/listinfo/flex-help > >> > > > > -- > Fabrício S. Paranhos > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > -- > Flex-help mailing list > Fle...@li... > https://lists.sourceforge.net/lists/listinfo/flex-help -- Will Estes Flex Project Maintainer wes...@gm... https://github.com/westes/flex |