This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c-exp.y


 > Basically, I want to revamp the way that GDB handles qualified names
 > in C++: these are names like C::x or C::D::y or whatever, where C
 > and/or D might be classes or namespaces.

A noble goal, but rather difficult, to say the least.

 > Unfortunately, some sort of distinction between types and
 > non-types seems to be hard-wired into the parser at a deep level: it
 > seems to be the parser's job to actually evaluate expressions
 > corresponding to types, whereas other expressions get evaluated by
 > somebody else.

Yes. This is a well-known issue with C++ parsing.  Consider

     (T) *x

We must know whether T is a type to know whether this is a cast.

Of course, the most infamous characteristic of C++ syntax is even
worse.  Even if you know that T is a type name, 

	T(x);

may be parsed either as a declaration of x or as an invocation of the
constructor for T on argument x (yielding a value of type T that is
voided).  The rule is that this is a declaration.  

 > Question 2: What should I do about it?

I hesitate to bring this up, but the newest versions of Bison support
GLR parsing, which can handle the infamous case.  In principle, one
could use GLR parsing to push off the distinction between types and
non-types to a later stage of the compiler, but this is probably not a
wise way to use it.  Still, I suspect that GLR parsing could clean up
at least some things in the C++ grammar.  Unfortunately, the feature
is new and experimental, and will need shaking down.  It is also not
in yacc or (at least for now) byacc, which may or may not be a problem.
On the other hand, I know for a fact that, starting next month, GLR's
contributer would be willing to work on getting the kinks out (;->).  

Paul Hilfinger


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]