[890] in java-interest
Re: Language spec syntax ambiguities
daemon@ATHENA.MIT.EDU (Jeremy Fitzhardinge)
Mon Aug 14 03:25:07 1995
From: "Jeremy Fitzhardinge" <jeremy@suede.sw.oz.au>
Date: Mon, 14 Aug 1995 13:55:34 -0500
In-Reply-To: "Scott Hudson" <hudson@cs.arizona.edu>
"Language spec syntax ambiguities" (Aug 11, 4:36pm)
To: "Scott Hudson" <hudson@cs.arizona.edu>, java-interest@java.sun.com
On Aug 11, 4:36pm, Scott Hudson wrote:
> I don't believe this is right (and its not what javac does). In
> particular, they allow a bunch of things that can't be right such as:
> "2+2 = 5", as well as some things which seem at least possibly right
> (they would be fine in ANSI C!), but which javac does not like such
> as: "(a) = 5" and "(a.b[5].c) = 5".
When writing a parser for this, I took the LHS of '=' to be a general
expression, and picked up the silly cases (non-lvalues) in semantic checking
later on.
> Clearly the left hand side of an assignment should be a more restricted
> syntactic class than the right side, but *exactly* what is that class?
I don't think it is really a syntactic issue - it's easier to get right in a
later stage of the compiler.
> We also have another production with a similar problem:
>
> Expression = Expression `(' ArgList? `)'
>
> Again, this is clearly wrong because you can't say "2+2()" and a more
> limited syntactic class for the function designator is surely required.
> However, its not obvious what that class should be. In particular, javac
> does not like "(f)(5)" and "(a.f)(5)" which seem a bit odd, but perfectly
> reasonable (and are again fine in ANSI C).
I took the method call syntax to be
mcall : expression "." IDENT '(' arglist? ')'
| IDENT '(' arglist? ')
Java doesn't allow calling methods indirectly (there's no pointer or reference
to method type), so there can only be a literal identifier before the argument
parens. I found this was easier to handle syntactically, so that casts and
general parenthesized expressions were easier to disambiguate (I think; I
haven't looked at that code for a while).
> Can we get a "ruling" on the exact syntax?
I gather that the grammar the in the appendix was not meant to be a formal
grammar for the language, but just a programmer's guide. I think there should
be a formal grammar which does contain all the intricasies of the syntax (Java
is only *apparently* very simple; while it's much simpler than C++, there are
some dark corners).
J
J
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com