Go Back   Rhinocerus > Newsgroup > Newsgroup comp.language.c++

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2012, 03:35 PM
Timothy Madden
Guest
 
Posts: n/a
Default Using declaration for a namespace name ?

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>
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

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 06-18-2012, 04:15 PM
Luca Risolia
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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::
}
Reply With Quote
  #3 (permalink)  
Old 06-18-2012, 05:18 PM
Timothy Madden
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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

Reply With Quote
  #4 (permalink)  
Old 06-18-2012, 06:39 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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 do not respond to top-posted replies, please don't ask
Reply With Quote
  #5 (permalink)  
Old 06-18-2012, 06:46 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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
Reply With Quote
  #6 (permalink)  
Old 06-22-2012, 05:33 PM
Timothy Madden
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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
Reply With Quote
  #7 (permalink)  
Old 06-22-2012, 05:40 PM
Paavo Helde
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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
Reply With Quote
  #8 (permalink)  
Old 06-22-2012, 06:39 PM
Rui Maciel
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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
Reply With Quote
  #9 (permalink)  
Old 06-25-2012, 10:08 AM
Jorgen Grahn
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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 .
Reply With Quote
  #10 (permalink)  
Old 07-16-2012, 07:15 PM
Jeff Flinn
Guest
 
Posts: n/a
Default Re: Using declaration for a namespace name ?

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
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:05 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.