Date: Mon, 28 Jul 2003 15:51:35 -0400 (EDT)
From: C. Scott Ananian
To: jsr14-prototype-comments@Sun.COM
Subject: Corrections to JSR-14 prototype 2.2 spec.
Appended is a corrected prototype 2.2 grammar, listed by section.
I've separately listed the changes I've made for each section, as well as
some comments on unclear portions.
This grammar can be converted to an LALR(1) grammar with no lexer
tricks using Eric Blake's refactorization of expressions; I can make a
CUP expression of this available if it is useful.
--scott
COBRA JUDY class struggle assassination Legion of Doom anthrax Echelon
early warning Mk 48 shortwave struggle non-violent protest SDI explosives
( http://cscott.net/ )
=========================================================================
Section 2.1 Type Syntax
-----------------------
ReferenceType ::= ClassOrInterfaceType
| ArrayType
| TypeVariable
TypeVariable ::= Identifier
ClassOrInterfaceType ::= ClassOrInterface TypeArgumentsOpt
ClassOrInterface ::= Identifier
| ClassOrInterfaceType . Identifier
TypeArguments ::= < TypeArgumentList >
TypeArgumentList ::= TypeArgument
| TypeArgumentList , TypeArgument
TypeArgument ::= ReferenceType
| Wildcard
Wildcard ::= ? WildcardBoundsOpt
WildcardBounds ::= extends ReferenceType
| super ReferenceType
[changes:
a) rename ActualTypeArguments to TypeArguments and
ActualTypeArgumentList to TypeArgumentList to be consistent with
TypeParameterList, etc naming.
b) fix capitalization on WildcardBoundsOpt in Wildcard production.
]
Section 2.2 Parameterized Type Declarations
-------------------------------------------
[no changes]
Section 2.4 Handling Consecutive Type Parameter Brackets
--------------------------------------------------------
ReferenceType ::= ClassOrInterfaceType
| ArrayType
| TypeVariable
ClassOrInterfaceType ::= ClassOrInterface
| ClassOrInterface TypeArguments
ClassOrInterface ::= Name
| ClassOrInterface TypeArguments DOT Name
ReferenceType1 ::= ReferenceType >
| ClassOrInterface < TypeArgumentsList2
ReferenceType2 ::= ReferenceType >>
| ClassOrInterface < TypeArgumentsList3
ReferenceType3 ::= ReferenceType >>>
TypeParameters ::= LT TypeParameterList1
TypeParameterList1 ::= TypeParameter1
| TypeParameterList , TypeParameter1
TypeParameter1 ::= TypeVariable >
| TypeVariable extends ReferenceType1
| TypeVariable extends ReferenceType AdditionalBoundList1
AdditionalBoundsList1 ::= AdditionalBound1
| AdditionalBound AdditionalBoundList1
AdditionalBound1 ::= & ReferenceType1
TypeArguments ::= LT TypeArgumentList1
TypeArgumentList1 ::= TypeArgument1
| TypeArgumentList, TypeArgument1
TypeArgumentList2 ::= TypeArgument2
| TypeArgumentList, TypeArgument2
TypeArgumentList3 ::= TypeArgument3
| TypeArgumentList, TypeArgument3
TypeArgument1 ::= ReferenceType1
| Wildcard1
TypeArgument2 ::= ReferenceType2
| Wildcard2
TypeArgument3 ::= ReferenceType3
| Wildcard3
Wildcard1 ::= ? >
| ? WildcardBounds1
WildcardBounds1 ::= extends ReferenceType1
| super ReferenceType1
Wildcard2 ::= ? >>
| ? WildcardBounds2
WildcardBounds2 ::= extends ReferenceType2
| super ReferenceType2
Wildcard3 ::= ? >>>
| WildcardBounds3
WildcardBounds3 ::= extends ReferenceType3
| super ReferenceType3
[changes: extensive. original grammar did not allow
type parameter: <T extends Object & Set<X>>
class type: A<List<?>>
]
3.1 Method Declarations
-----------------------
[no changes]
3.3 Generic Constructors
------------------------
ConstructorDeclaration ::= ConstructorModifiersOpt ConstructorDeclarator
ThrowsOpt ConstructorBody
ConstructorDeclarator ::= TypeParametersOpt SimpleTypeName
( FormalParameterListOpt )
[changes:
a) TypeArgumentsOpt changed to TypeParametersOpt in production for
ConstructorDeclarator
]
5.1 Class Instance Creation Expressions
---------------------------------------
ClassInstanceCreationExpression ::= new TypeArgumentsOpt
ClassOrInterfaceType ( ArgumentListOpt ) ClassBodyOpt
| Primary . new TypeArgumentsOpt
Identifier TypeArgumentsOpt ( ArgumentListOpt ) ClassBodyOpt
[changes:
a) Removed extra TypeArgumentsOpt from first alternative
b) Fixed position of 'new' vs TypeArgumentsOpt in both alternatives
comments:
a) Is 'Name' intended to be a valid 'Primary'?
current prototype allows this; JLS grammar is unclear. (sun bug 4750181)
current prototype also does *not* accept the first alternative in
this production, e.g. '<A> new B()'
]
5.2 Explicit Constructor Invocations
------------------------------------
ExplicitConstructorInvocation ::= TypeArgumentsOpt this ( ArgumentListOpt )
| TypeArgumentsOpt super ( ArgumentListOpt )
| Primary . TypeArgumentsOpt super ( ArgumentListOpt )
[comments:
a) again, is 'Name' intended to be a valid 'Primary'?
]
5.3 Array Creation Expressions
------------------------------
[no changes]
5.6 Generic Method Invocation
-----------------------------
MethodInvocation ::= MethodExpr ( ArgumentListOpt )
MethodExpr ::= MethodName
| Primary . TypeArgumentsOpt Identifier
| super . TypeArgumentsOpt Identifier
| Name . super . TypeArgumentsOpt Identifier
[changes:
a) 'ClassName' to 'Name' -- this is perhaps spurious
b) Removed 'TypeArgumentsOpt' from first alternative; this is to
resolve the A((B)<C,D>E()) ambiguity. Example 18 must be
changed; some text should also address this non-orthogonality.
comments:
a) Current implementation allows 'Name' as a 'Primary', e.g.
A.<B>foo();
Presumably this *is* the intended behavior, as the first
alternative in the MethodExpr production is not accepted by the
prototype, e.g. '<B>foo();'
b) If Name is a Primary and Name is a MethodName, then there is an
ambiguity in the parse for 'a.b()'.
]