Thread: [Flex-help] Error changing yylex return.
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Fabricio S. P. <fab...@gm...> - 2016-02-29 22:06:23
|
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 |
From: Chris v. <che...@gm...> - 2016-03-01 01:37:57
|
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 > |
From: Fabricio S. P. <fab...@gm...> - 2016-03-02 01:13:54
|
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 |
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 |
From: Fabricio S. P. <fab...@gm...> - 2016-03-02 14:14:09
|
> What version of flex are you running? flex 2.5.39 |
From: Chris v. <che...@gm...> - 2016-03-05 02:33:35
|
I gave this a shot on my own (using the same version) and got it working with a tweak. My next question: where did lex.yy.h come from? As far as I know, flex does not generate header files unless you put it in C++ mode. I got your main.c to compile by changing its include from "lex.yy.h" to "lex.yy.c", and the resulting binary recognizes "test" input and prints out "T: 2.000000". Of course the best-practices answer is to not to #include a .c file, but rather add a bunch of extern declarations and link, blah blah blah... But the point is the YY_DECL worked. -Chris On Wed, Mar 2, 2016 at 6:13 AM, Fabricio S. Paranhos < fab...@gm...> wrote: > > What version of flex are you running? > > flex 2.5.39 > > > ------------------------------------------------------------------------------ > 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 > |
From: Fabricio S. P. <fab...@gm...> - 2016-03-05 16:30:52
|
On 03/04/2016 11:33 PM, Chris verBurg wrote: > I gave this a shot on my own (using the same version) and got it working > with a tweak. My next question: where did lex.yy.h come from? As far as I > know, flex does not generate header files unless you put it in C++ mode. I > got your main.c to compile by changing its include from "lex.yy.h" to > "lex.yy.c", and the resulting binary recognizes "test" input and prints out > "T: 2.000000". Chris the lex.yy.h came from flex command line option: Files: -o, --outfile=FILE specify output filename -S, --skel=FILE specify skeleton file -t, --stdout write scanner on stdout instead of lex.yy.c --yyclass=NAME name of C++ class --header-file=FILE create a C header file in addition to the scanner --header-file option > Of course the best-practices answer is to not to #include a .c file, but > rather add a bunch of extern declarations and link, blah blah blah... But > the point is the YY_DECL worked. > > -Chris > > > On Wed, Mar 2, 2016 at 6:13 AM, Fabricio S. Paranhos < > fab...@gm...> wrote: > >>> What version of flex are you running? >> >> flex 2.5.39 >> >> >> ------------------------------------------------------------------------------ >> 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 |