-
Enhancement
-
Resolution: Fixed
-
P4
-
7
-
None
-
Verified
In the DocBook source for JLS7, a grammar is represented as a <literallayout> because most of a grammar is monospaced. The FO stylesheets accurately render emphasized or serif text which appears in a <literallayout>, but the HTML stylesheets do not. Essentially this means a grammar in a PDF includes styled text but a grammar on a Web page is monospaced throughout. This causes two problems. First, in the chapters, grammars don't distinguish terminals from non-terminals. Second, in chapter 18, the BNF meta-characters {} and [] look the same as the Java terminals {} and []. Separately. there are obscure problems in the HTML rendering, such as insufficient indentation for NormalInterfaceDeclaration in 9.1.
As well as formatting headaches (which were present long before JLS7), the fact that chapter 18 presents a different grammar than the preceding chapters is both a surprise to readers and a nightmare for maintainers. There has been a long bug parade of infelicities in the chapter 18 grammar, withJDK-7080366 being the latest. As the Java language grows more complex (e.g. lambda expressions, type annotations), it is not tenable - or necessary - to maintain a distinct and allegedly LALR(1) grammar in chapter 18. Readers will be better served by recapping the productions from chapters 2-15.
The DocBook-EBNF schema offers a solution to both the formatting headaches and the need to "manage" grammars by cross-referencing them and recapping them. Non-terminals are first class, so the use of a non-terminal is hyperlinked to its definition in both HTML and PDF.
For best results, some stylistic changes to the grammars in chapters 2-15 are needed:
1) It is necessary to drop the "opt" subscript and denote optionality with [] characters. For consistency, the {} characters used to denote repetition in JLS7 ch.18 are adopted too. These notations are to be explained in JLS 2.4 "Grammar Notation".
2) An idiom in JLS7 was FooThings_opt, where FooThings was either FooThing or FooThings FooThing. With the ability to denote repetition, FooThings_opt is replaced with {FooThing} and the FooThings nonterminal is removed. Namely, the following nonterminals are removed in JLS8:
- InputElements (3.5)
- CharactersInLine (3.7)
- StringCharacters (3.10.5)
- AdditionalBoundList (4.4)
- ImportDeclarations (7.3)
- TypeDeclarations (7.3)
- ClassModifiers (8.1)
- ClassBodyDeclarations (8.1.6)
- FieldModifiers (8.3)
- MethodModifiers (8.4)
- VariableModifiers (8.4.1)
- ConstructorModifiers (8.8)
- InterfaceModifiers (9.1)
- InterfaceMemberDeclarations (9.1.4)
- ConstantModifiers (9.3)
- AbstractMethodModifiers (9.4)
- AnnotationTypeElementDeclarations (9.6)
- Annotations (9.7)
- SwitchBlockStatementGroups (14.11)
3) The ability to denote repetition also causes changes to nonterminals that were defined recursively:
- UnicodeMarker (3.3)
- IdentifierChars (3.8)
- DigitsAndUnderscores (3.10.1)
- Underscores (3.10.1)
- HexDigitsAndUnderscores (3.10.1)
- OctalDigitsAndUnderscores (3.10.1)
- BinaryDigitsAndUnderscores (3.10.1)
- TypeName (4.3)
- TypeArgumentList (4.5.1)
- TypeParameterList (8.1.2)
- InterfaceTypeList (8.1.5)
- VariableDeclarators (8.3, but see below)
- VariableDeclaratorId (8.3)
- MethodDeclarator (8.4, "obsolescent production" that allowed trailing [])
- FormalParameters (8.4.1)
- ExceptionTypeList (8.4.6)
- EnumConstants (8.9.1, but see below)
- ElementValuePairs (9.7.1, but see below)
- ElementValues (9.7.1, but see below)
- VariableInitializers (10.6, but see below)
- BlockStatements (14.2)
- SwitchLabels (14.11)
- StatementExpressionList (14.14.1)
- Catches (14.20)
- CatchType (14.20)
- Resources (14.20.3, but see below)
- ArgumentList (15.9)
- DimExprs (15.10)
- Dims (15.10)
4) The following productions which denote comma-separated lists are renamed for consistency with other list-like productions:
- VariableDeclarators to VariableDeclaratorList (8.3)
- EnumConstants to EnumConstantList (8.9.1)
- ElementValuePairs to ElementValuePairList (9.7.1)
- ElementValues to ElementValueList (9.7.1)
- VariableInitializers to VariableInitializerList (10.6)
- Resources to ResourceList (14.20.3)
5) The following productions are renamed for consistency:
- Super to Superclass (8.1.4)
- Interfaces to Superinterfaces (8.1.5)
6) The translations of the enhanced for statement and the try-with-resources statement use grammar notation, and must be updated.
As well as formatting headaches (which were present long before JLS7), the fact that chapter 18 presents a different grammar than the preceding chapters is both a surprise to readers and a nightmare for maintainers. There has been a long bug parade of infelicities in the chapter 18 grammar, with
The DocBook-EBNF schema offers a solution to both the formatting headaches and the need to "manage" grammars by cross-referencing them and recapping them. Non-terminals are first class, so the use of a non-terminal is hyperlinked to its definition in both HTML and PDF.
For best results, some stylistic changes to the grammars in chapters 2-15 are needed:
1) It is necessary to drop the "opt" subscript and denote optionality with [] characters. For consistency, the {} characters used to denote repetition in JLS7 ch.18 are adopted too. These notations are to be explained in JLS 2.4 "Grammar Notation".
2) An idiom in JLS7 was FooThings_opt, where FooThings was either FooThing or FooThings FooThing. With the ability to denote repetition, FooThings_opt is replaced with {FooThing} and the FooThings nonterminal is removed. Namely, the following nonterminals are removed in JLS8:
- InputElements (3.5)
- CharactersInLine (3.7)
- StringCharacters (3.10.5)
- AdditionalBoundList (4.4)
- ImportDeclarations (7.3)
- TypeDeclarations (7.3)
- ClassModifiers (8.1)
- ClassBodyDeclarations (8.1.6)
- FieldModifiers (8.3)
- MethodModifiers (8.4)
- VariableModifiers (8.4.1)
- ConstructorModifiers (8.8)
- InterfaceModifiers (9.1)
- InterfaceMemberDeclarations (9.1.4)
- ConstantModifiers (9.3)
- AbstractMethodModifiers (9.4)
- AnnotationTypeElementDeclarations (9.6)
- Annotations (9.7)
- SwitchBlockStatementGroups (14.11)
3) The ability to denote repetition also causes changes to nonterminals that were defined recursively:
- UnicodeMarker (3.3)
- IdentifierChars (3.8)
- DigitsAndUnderscores (3.10.1)
- Underscores (3.10.1)
- HexDigitsAndUnderscores (3.10.1)
- OctalDigitsAndUnderscores (3.10.1)
- BinaryDigitsAndUnderscores (3.10.1)
- TypeName (4.3)
- TypeArgumentList (4.5.1)
- TypeParameterList (8.1.2)
- InterfaceTypeList (8.1.5)
- VariableDeclarators (8.3, but see below)
- VariableDeclaratorId (8.3)
- MethodDeclarator (8.4, "obsolescent production" that allowed trailing [])
- FormalParameters (8.4.1)
- ExceptionTypeList (8.4.6)
- EnumConstants (8.9.1, but see below)
- ElementValuePairs (9.7.1, but see below)
- ElementValues (9.7.1, but see below)
- VariableInitializers (10.6, but see below)
- BlockStatements (14.2)
- SwitchLabels (14.11)
- StatementExpressionList (14.14.1)
- Catches (14.20)
- CatchType (14.20)
- Resources (14.20.3, but see below)
- ArgumentList (15.9)
- DimExprs (15.10)
- Dims (15.10)
4) The following productions which denote comma-separated lists are renamed for consistency with other list-like productions:
- VariableDeclarators to VariableDeclaratorList (8.3)
- EnumConstants to EnumConstantList (8.9.1)
- ElementValuePairs to ElementValuePairList (9.7.1)
- ElementValues to ElementValueList (9.7.1)
- VariableInitializers to VariableInitializerList (10.6)
- Resources to ResourceList (14.20.3)
5) The following productions are renamed for consistency:
- Super to Superclass (8.1.4)
- Interfaces to Superinterfaces (8.1.5)
6) The translations of the enhanced for statement and the try-with-resources statement use grammar notation, and must be updated.
- relates to
-
JDK-1201483 Java Language Spec needs grammar appendix
-
- Closed
-
-
JDK-7080366 Grammar bugs in JLS7
-
- Closed
-