Topic: Is this an ambiguity?


Author: simonh@swidev.demon.co.uk (Simon Huntington)
Date: Thu, 23 Sep 1993 19:02:13 +0000
Raw View
In article <27p42b$20l@agate.berkeley.edu> hilfinger@CS.Berkeley.EDU writes:

>The following question seems so obvious that I will humbly accept any
>berating I get for not having seen the answer.  Consider the declaration
>
>        A::B::C::* x(int);
>
>This seems a legal pointer-to-member declaration under the syntax, but
>seems to have two interpretations:
>
>        A::B (::C::*x)(int);
>
>and
>
>        A (::B::C::*x)(int);
>
>What's the deal?


I think this is an oversight in the original ARM grammar (in my opinion). I
discovered this problem while writing a parser for C++. I decided to modify
the grammar so pointer-to-members can only be qualified, rather than been
completely qualified with the global ::.

 for example:

  A::B::C::* x(int);


 is taken as:
  int A::B::C::* x(int);



 the other examples:
  A::B (::C::*x)(int)  -> A::B C::* x(int);
  && A (::B::C::*x)(int)  -> A B::C::* x(int);




My reason for doing this is that declarators can only be qualified, not
completely qualified. Surely the same should apply to other declarators.

This is the only way the problem can be resolved without parsing the entire
declaration and then backtracking if that parse fails. This is very dodgy
ground, so I think it's best disambiguate the grammar.


Any flames?



--
Simon Huntington
Software Interrupt Developments. Leeds, UK.




Author: hilfingr@tully.CS.Berkeley.EDU (Paul N. Hilfinger)
Date: 22 Sep 1993 08:57:47 GMT
Raw View
The following question seems so obvious that I will humbly accept any
berating I get for not having seen the answer.  Consider the declaration

 A::B::C::* x(int);

This seems a legal pointer-to-member declaration under the syntax, but
seems to have two interpretations:

 A::B (::C::*x)(int);

and

 A (::B::C::*x)(int);

What's the deal?

P. Hilfinger




Author: kanze@us-es.sel.de (James Kanze)
Date: 23 Sep 93 16:11:37
Raw View
In article <27p42b$20l@agate.berkeley.edu>
hilfingr@tully.CS.Berkeley.EDU (Paul N. Hilfinger) writes:

|> The following question seems so obvious that I will humbly accept any
|> berating I get for not having seen the answer.  Consider the declaration

|>  A::B::C::* x(int);

If this is a legal declaration, it is only one because of the
implicite int rule, and is thus the equivalent of:

 int A::B::C::* x( int ) ;

This is an external declaration of a function taking an int as
parameter, and returning a pointer to int member of A::B::C.

(I hesitate to say if and when the initial example would be legal.  I
consider any use of the implicite int rule atrociously bad style, and
so have made no effort to learn where it may be applied.)

|> This seems a legal pointer-to-member declaration under the syntax, but
|> seems to have two interpretations:

|>  A::B (::C::*x)(int);

|> and

|>  A (::B::C::*x)(int);

|> What's the deal?

Both of the above are completely different.  By adding the
parentheses, you have given an explicite type, and changed the
declaration to: pointer to function member of global C taking an int
parameter and returning an A::B, and pointer to function member of
global B::C taking an in parameter and returning an A..
--
James Kanze                             email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                   -- Beratung in industrieller Datenverarbeitung




Author: reindorf@fulcrum.co.uk (Charles Reindorf)
Date: Thu, 23 Sep 1993 16:51:46 GMT
Raw View
 On 23 Sep 93, James Kanze wrote

> In article <27p42b$20l@agate.berkeley.edu>
> hilfingr@tully.CS.Berkeley.EDU (Paul N. Hilfinger) writes:

> |> The following question seems so obvious that I will humbly accept any
> |> berating I get for not having seen the answer.  Consider the declaration

> |>  A::B::C::* x(int);

> If this is a legal declaration, it is only one because of the
> implicite int rule, and is thus the equivalent of:

> int A::B::C::* x( int ) ;

I dont think the poster was referring to the "implicit int" rule
at all, and we could assume for the purpose of this example that
the implicit "int" rule did not exist (although given that it
does exist, and assuming it can be applied above, it would lend
even further ambiguity to the construct).

> This is an external declaration of a function taking an int as
> parameter, and returning a pointer to int member of A::B::C.

> (I hesitate to say if and when the initial example would be legal.  I
> consider any use of the implicite int rule atrociously bad style, and
> so have made no effort to learn where it may be applied.)

> |> This seems a legal pointer-to-member declaration under the syntax, but
> |> seems to have two interpretations:

> |>  A::B (::C::*x)(int);

> |> and

> |>  A (::B::C::*x)(int);

> |> What's the deal?

> Both of the above are completely different.  By adding the
> parentheses, you have given an explicite type, and changed the
> declaration to: pointer to function member of global C taking an int
> parameter and returning an A::B, and pointer to function member of
> global B::C taking an in parameter and returning an A..


Probably what was meant was :-

Can "A::B::C::* x(int)" be interpreted as ...

    A::B (::C::*x(int));

or as ...

    A (::B::C::*x(int));

... I.e. How do you tell where the type specifier bit ends and the
declarator bit starts? Presumably there is someone out there who
does not need to spend 1/2 hour digging around inside the ARM to
come up with an inconclusive result.

> --
> James Kanze                             email: kanze@us-es.sel.de
> GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
> Conseils en informatique industrielle --
> -- Beratung in industrieller Datenverarbeitung

--- Charles Reindorf