[893] in java-interest

home help back first fref pref prev next nref lref last post

Re: Language spec syntax ambiguities

daemon@ATHENA.MIT.EDU (Scott Hudson)
Mon Aug 14 05:25:43 1995

From: hudson@cc.gatech.edu (Scott Hudson)
To: java-interest@java.sun.com
Date: Mon, 14 Aug 1995 01:25:49 -0400 (EDT)

Jeremy Fitzhardinge <jeremy@suede.sw.oz.au> writes:
> On Aug 11,  4:36pm, Scott Hudson wrote:
>> 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.

Well, you're right its a matter of taste/design decision.  I guess I lean
pretty strongly to the "do it in syntax if you can" camp on this issue -- 
particuarly for purposes of a language spec.  In that instance doing it 
with a grammar is highly desirable since there is typically not much to 
interpret and no question about exactly what it means.

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

This is more or less what I'm looking for.  However, I don't believe
this is quite right for a couple of reasons.  First, you can also say
"super(x,y,z)" and "this(x,y,z)" inside a constructor (I suppose by my
argument above we should special case constructor bodies, but ...).
Also, I'd argue for something lower down the precidence chain than
expression since this allows "2+2.foo = 5;" which brings us back to the
same issue.  Finally, this introduces another ambiguity.  "a+b" is a
valid expression so does "a+b.c = 5" mean "(a+b).c = 5" here (that's
the parse tree you get)?

Scott
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post