|
|||
|
Hello
I have a header file, generated with flex++, that declares a class phpFlexLexer in the global namespace. I would like to include this header in the yy namespaces, like this: namespace yy { #include "FlexLexer.h" } so the class would than be yy: hpFlexLexer, but than the standardheaders included by FlexLexer.h would declare symbols in namespace yy::std this way. Is there a way to write a using-declaration that brings the global name std into namespace yy ? So that if I later #include <iostream> from namespace yy, than any attempts to populate yy::std would really populate the global namespace std ? Or maybe it is just ok to populate yy::std and let things go this way ? Thank you, Timothy Madden |
|
|
||||
|
||||
|
|
|
|||
|
On 18/06/2012 17:35, Timothy Madden wrote:
> Hello > > I have a header file, generated with flex++, that declares a class > phpFlexLexer in the global namespace. > > I would like to include this header in the yy namespaces, like this: > > namespace yy > { > #include "FlexLexer.h" > } > > so the class would than be yy: hpFlexLexer, but than the standard> headers included by FlexLexer.h would declare symbols in namespace > yy::std > this way. Is there a way to write a using-declaration that brings the > global name std into namespace yy ? So that if I later #include > <iostream> Cannot you modify FlexLexer.h, after it has been generated, for e.g. // FlexLexer.h #include <iostream> namespace yy { using namespace std; // any FlexLexer-related declaration using symbols in std:: } |
|
|||
|
On Mon, 18 Jun 2012 18:15:33 +0200, Luca Risolia wrote:
> On 18/06/2012 17:35, Timothy Madden wrote: >> Hello >> >> I have a header file, generated with flex++, that declares a class >> phpFlexLexer in the global namespace. >> >> I would like to include this header in the yy namespaces, like this: >> >> namespace yy { >> #include "FlexLexer.h" >> } >> >> so the class would than be yy: hpFlexLexer, but than the standard>> headers included by FlexLexer.h would declare symbols in namespace >> yy::std this way. Is there a way to write a using-declaration that >> brings the global name std into namespace yy ? So that if I later >> #include <iostream> > > Cannot you modify FlexLexer.h, after it has been generated, for e.g. > > // FlexLexer.h > > #include <iostream> > > namespace yy { > using namespace std; > // any FlexLexer-related declaration using symbols in std:: > } If I modify the file after it has been generated, than I would have to modify it after each and every time it is generated. My question is how to bring the name `std`, into my yy namespace, and only that name. That using-declaration you showed me would bring in the entire content of the std namespace (which is not what I want). What I would like is to do something like this: namespace std { } namespace yy { using ::std; #include <iostream> } That way, the included <iostream> would populate namespace ::std, although it is included from namespace yy; My question is if the using ::std; statement is correct in C++ and would work as expected, or if there is a better alternative to it. Thank you, Timothy Madden |
|
|||
|
On 6/18/2012 11:35 AM, Timothy Madden wrote:
> Hello > > I have a header file, generated with flex++, that declares a class > phpFlexLexer in the global namespace. > > I would like to include this header in the yy namespaces, like this: > > namespace yy > { > #include "FlexLexer.h" > } That's A Bad Idea(tm). Why don't you include that header from within another class defined in a function inside a macro expansion? > so the class would than be yy: hpFlexLexer, but than the standardthen > headers included by FlexLexer.h would declare symbols in namespace > yy::std Would they? Perhaps it's a bad implementation. Why can't they declare the symbos in ::std? Of course, normal library implementers rarely write their headers to overcome inclusion inside another namespace... because nobody writes it that way! > this way. Is there a way to write a using-declaration that brings the > global name std into namespace yy ? So that if I later #include > <iostream> > from namespace yy, than any attempts to populate yy::std would really > populate the global namespace std ? I don't know of any way. Maybe a namespace alias?... namespace yy { namespace std = ::std; ... } > Or maybe it is just ok to populate yy::std and let things go this way ? So, you're saying that you haven't even tried? V -- I do not respond to top-posted replies, please don't ask |
|
|||
|
On 6/18/2012 1:18 PM, Timothy Madden wrote:
> On Mon, 18 Jun 2012 18:15:33 +0200, Luca Risolia wrote: > >> On 18/06/2012 17:35, Timothy Madden wrote: >>> Hello >>> >>> I have a header file, generated with flex++, that declares a class >>> phpFlexLexer in the global namespace. >>> >>> I would like to include this header in the yy namespaces, like this: >>> >>> namespace yy { >>> #include "FlexLexer.h" >>> } >>> >>> so the class would than be yy: hpFlexLexer, but than the standard>>> headers included by FlexLexer.h would declare symbols in namespace >>> yy::std this way. Is there a way to write a using-declaration that >>> brings the global name std into namespace yy ? So that if I later >>> #include<iostream> >> >> Cannot you modify FlexLexer.h, after it has been generated, for e.g. >> >> // FlexLexer.h >> >> #include<iostream> >> >> namespace yy { >> using namespace std; >> // any FlexLexer-related declaration using symbols in std:: >> } > > If I modify the file after it has been generated, than I would have to > modify it after each and every time it is generated. Right. If you let some tool generate your headers, what stops you from writing your own tool that, after the other tools is done generating the header, makes a slight modification to it? > My question is how to bring the name `std`, into my yy namespace, and > only that name. That using-declaration you showed me would bring in the > entire content of the std namespace (which is not what I want). > > What I would like is to do something like this: > > namespace std > { > } > > namespace yy > { > using ::std; I'd try namespace std = ::std; > #include<iostream> > } > > That way, the included<iostream> would populate namespace ::std, > although it is included from namespace yy; > > My question is if the using ::std; statement is correct in C++ No, since 'std' is not an entity name, it's a namespace. > and would > work as expected, or if there is a better alternative to it. Perhaps a better alternative is to add your modification into the generation of the header toolchain. V -- I do not respond to top-posted replies, please don't ask |
|
|||
|
On 06/18/2012 09:39 PM, Victor Bazarov wrote:
> On 6/18/2012 11:35 AM, Timothy Madden wrote: >> Hello >> >> I have a header file, generated with flex++, that declares a class >> phpFlexLexer in the global namespace. >> >> I would like to include this header in the yy namespaces, like this: >> >> namespace yy >> { >> #include "FlexLexer.h" >> } > > That's A Bad Idea(tm). Why don't you include that header from within > another class defined in a function inside a macro expansion? > >> so the class would than be yy: hpFlexLexer, but than the standard> > then > >> headers included by FlexLexer.h would declare symbols in namespace >> yy::std > > Would they? Perhaps it's a bad implementation. Why can't they declare > the symbos in ::std? Of course, normal library implementers rarely write > their headers to overcome inclusion inside another namespace... because > nobody writes it that way! > >> this way. Is there a way to write a using-declaration that brings the >> global name std into namespace yy ? So that if I later #include >> <iostream> >> from namespace yy, than any attempts to populate yy::std would really >> populate the global namespace std ? > > I don't know of any way. Maybe a namespace alias?... > > namespace yy { > namespace std = ::std; > ... > } > > >> Or maybe it is just ok to populate yy::std and let things go this way ? > > So, you're saying that you haven't even tried? > > V I know my #include inside a namespace is a bad idea, but flex has no namespaces for its C++ interface, so the bad idea is all I can try to get it. Well I tried the namespace alias, and the compiler accepted the statement, but I still get errors later in the included system headers this way. So I resorted to making sure that I include any headers needed by FlexLexer.h before I open yy namespace. That way, when FlexLexer.h includes them, their include guards would simply skip all their content. And yes, I have not even tried until now, because I am just learning flex and bison, and believe me, trying to integrate them with their C++ interface, for the first time, is not fun! Thank you, Timothy Madden |
|
|||
|
Timothy Madden <terminatorul@gmail.com> wrote in news:4fe4ac69$0$288
$14726298@news.sunsite.dk: > > I know my #include inside a namespace is a bad idea, but flex has no > namespaces for its C++ interface, so the bad idea is all I can try to > get it. > > Well I tried the namespace alias, and the compiler accepted the > statement, but I still get errors later in the included system headers > this way. So I resorted to making sure that I include any headers needed > by FlexLexer.h before I open yy namespace. That way, when FlexLexer.h > includes them, their include guards would simply skip all their content. > > And yes, I have not even tried until now, because I am just learning > flex and bison, and believe me, trying to integrate them with their C++ > interface, for the first time, is not fun! So, why don't you try Boost Spirit? AFAIK it should do about the same as flex/yacc, and in a very C++ manner. Haven't used it myself though. hth Paavo |
|
|||
|
Timothy Madden wrote:
> I know my #include inside a namespace is a bad idea, but flex has no > namespaces for its C++ interface, so the bad idea is all I can try to > get it. Why not file a bug report describing your problem? This appears to be an important issue, which might affect a considerable number of users, and may not be that hard to implement. Rui Maciel |
|
|||
|
On Fri, 2012-06-22, Rui Maciel wrote:
> Timothy Madden wrote: > >> I know my #include inside a namespace is a bad idea, but flex has no >> namespaces for its C++ interface, so the bad idea is all I can try to >> get it. > > Why not file a bug report describing your problem? This appears to be an > important issue, which might affect a considerable number of users, and may > not be that hard to implement. Also note, the flex manual documents the C++ generator as experimental: *IMPORTANT*: the present form of the scanning class is _experimental_ and may change considerably between major releases. Last time I checked (which may be ten years ago or so) the manual said the same thing. I got the impression that someone, in the 1980s or early 1990s, thought it would be neat to try OOP ideas in flex, and that code is still there, with minimal maintenance and few users. That time I decided to use the C code generator instead and encapsulate it myself. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
|
|||
|
On 7/15/2012 5:45 PM, Jorgen Grahn wrote:
> On Tue, 2012-07-03, Victor Bazarov wrote: >> On 7/3/2012 8:34 AM, Timothy Madden wrote: >>> [..] I posted a >>> question on gmane.comp.lex.flex.general, only to find out flex is no >>> longer being developed (only some minimal maintenance). .... > (And to reiterate what I wrote here earlier: I wouldn't touch its > ancient experimental C++ code generator with a ten-foot pole.) > >> I am certain that if there is a need in the tools like >> flex or bison, there are replacements. Good luck! > > If flex is good enough for enough people, that might be a problem. > > Also, since the heyday of lexers in the 1980s, CPU power had become > very cheap and powerful regex libraries and scripting languages have > become common. This is just speculation, but that may be another force > working against it. Or use boost spirit qi to directly access ebnf/peg parsing technology directly from C++. Jeff |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|