Topic: [QUERY] C++ ambiguties -- is this right?
Author: Jason Merrill <jason@cygnus.com>
Date: 1997/01/08 Raw View
>>>>> John Lilley <jlilley@empathy.com> writes:
> then I parse this:
> g(int(x), int(y)), h(int(z), int(3));
> as declaring g as a function, and h as a variable with (too many)
> initializers.
> This one:
> g(int(x), int(y)), h(int(z), int(3)), 5;
> I parse as a comma-expression calling g() and h() and finally yielding
> 5.
> I'm unclear as to the status of declarations with no
> declaration-specifiers. Are they still allowed in the latest draft?
They were never allowed as a statement, only at top level, and those are no
longer allowed, either.
> Even if they are disallowed, is this sort of stuff still a practical
> consideration for C++ parser wishing to handle old-style function
> declarations?
It is still a consideration regardless of old-style function declarations.
The decl/expr ambiguity is a pain for the compiler to deal with; you
basically have to read in the statement, decide what it is, and then start
over and parse it.
Jason
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: jlilley@empathy.com (John Lilley)
Date: 1997/01/07 Raw View
I have a question concering the dreaded declaration/expression
ambiguities in C++. This is how my C++ parser treats the cases
described below. Am I handling this right?
Context: this is in a code block where statements are parsed.
Assuming that declarations with no declaration-specifiers are allowed,
then I parse this:
g(int(x), int(y)), h(int(z), int(3));
as declaring g as a function, and h as a variable with (too many)
initializers. This bothers me -- since it is not valid to declare
variables with no declaration-specifiers, then should this
interpretation be rejected in favor of a comma-expression calling g()
and h()?
This one:
g(int(x), int(y)), h(int(z), int(3)), 5;
I parse as a comma-expression calling g() and h() and finally yielding
5.
I'm unclear as to the status of declarations with no
declaration-specifiers. Are they still allowed in the latest draft?
Even if they are disallowed, is this sort of stuff still a practical
consideration for C++ parser wishing to handle old-style function
declarations?
thanks,
john lilley
--
Send compilers articles to compilers@iecc.com,
meta-mail to compilers-request@iecc.com.