Docsity

Java Language Grammar - Programming Language Translation - Lecture Slides, Slides of Programming Languages

Toggle sidebar
bg1
The Java Language Grammar
http://java.sun.com/docs/books/jls/index.html
http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html
Contents | Prev | Next | Index Java Language Specification
Second Edition
---------------------------------------------------------------------------
CHAPTER 18
Syntax
---------------------------------------------------------------------------
This chapter presents a grammar for the Java programming language.
The grammar presented piecemeal in the preceding chapters is much better
for exposition, but it is not ideally suited as a basis for a parser. The
grammar presented in this chapter is the basis for the reference
implementation.
The grammar below uses the following BNF-style conventions:
* [x] denotes zero or one occurrences of x.
* {x} denotes zero or more occurrences of x.
* x | y means one of either x or y.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Language Grammar - Programming Language Translation - Lecture Slides and more Slides Programming Languages in PDF only on Docsity!

http://java.sun.com/docs/books/jls/index.html

http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html

Contents | Prev | Next | Index Java Language Specification Second Edition


CHAPTER 18 Syntax


This chapter presents a grammar for the Java programming language. The grammar presented piecemeal in the preceding chapters is much better for exposition, but it is not ideally suited as a basis for a parser. The grammar presented in this chapter is the basis for the reference implementation. The grammar below uses the following BNF-style conventions:

  • [x] denotes zero or one occurrences of x.
  • {x} denotes zero or more occurrences of x.
  • x | y means one of either x or y.

The Java Language Keywords

3.9 Keywords

The following character sequences, formed from ASCII letters,

are reserved for use as keywords and cannot be used as identifiers (§3.8):

Keyword: one of

abstract default if private this

boolean do implements protected throw

break double import public throws

byte else instanceof return transient

case extends int short try

catch final interface static void

char finally long strictfp volatile

class float native super while

const for new switch

continue goto package synchronized

Infixop: "||" | && | "|" | ^ | & | == | != | < | > | <= | >= | << | >> | >>> | + | - | * | / | % Expression3: PrefixOp Expression3 | ( Expr | Type ) Expression3 | Primary {Selector} {PostfixOp} Primary: ( Expression ) | this [Arguments] | super SuperSuffix | Literal | new Creator | Identifier {. Identifier }[ IdentifierSuffix] | BasicType BracketsOpt .class | void.class | IdentifierSuffix: [ ( ] BracketsOpt. class | Expression ]) | Arguments |

. ( class | this | super Arguments | new InnerCreator ) | PrefixOp: ++ | -- |! | ~ | + | - PostfixOp: ++ | -- Selector:. Identifier [Arguments] | . this | . super SuperSuffix | . new InnerCreator | [ Expression ]

SuperSuffix: Arguments |

. Identifier [Arguments] BasicType: byte | short | char | int | long | float | double | boolean ArgumentsOpt: [ Arguments ] Arguments: ( [Expression { , Expression }] ) BracketsOpt: {[]} Creator: QualifiedIdentifier ( ArrayCreatorRest | ClassCreatorRest ) InnerCreator: Identifier ClassCreatorRest ArrayCreatorRest: [ ( ] BracketsOpt ArrayInitializer | Expression ] {[ Expression ]} BracketsOpt ) ClassCreatorRest: Arguments [ClassBody] ArrayInitializer: { [VariableInitializer {, VariableInitializer} [,]] } VariableInitializer: ArrayInitializer | Expression

SwitchBlockStatementGroups: { SwitchBlockStatementGroup } SwitchBlockStatementGroup: SwitchLabel BlockStatements SwitchLabel: case ConstantExpression : | default: MoreStatementExpressions: { , StatementExpression } ForInit: StatementExpression MoreStatementExpressions | [final] Type VariableDeclarators ForUpdate: StatementExpression MoreStatementExpressions ModifiersOpt: { Modifier } Modifier: public | protected | private | static | abstract | final | native | synchronized | transient | volatile | strictfp VariableDeclarators: VariableDeclarator { , VariableDeclarator } VariableDeclaratorsRest: VariableDeclaratorRest { , VariableDeclarator } ConstantDeclaratorsRest: ConstantDeclaratorRest { , ConstantDeclarator } VariableDeclarator: Identifier VariableDeclaratorRest ConstantDeclarator: Identifier ConstantDeclaratorRest

VariableDeclaratorRest: BracketsOpt [ = VariableInitializer] ConstantDeclaratorRest: BracketsOpt = VariableInitializer VariableDeclaratorId: Identifier BracketsOpt CompilationUnit: [package QualifiedIdentifier ; ] {ImportDeclaration} {TypeDeclaration} ImportDeclaration: import Identifier {. Identifier } [. * ] ; TypeDeclaration: ClassOrInterfaceDeclaration | ; ClassOrInterfaceDeclaration: ModifiersOpt (ClassDeclaration | InterfaceDeclaration) ClassDeclaration: class Identifier [extends Type] [implements TypeList] ClassBody InterfaceDeclaration: interface Identifier [extends TypeList] InterfaceBody TypeList: Type { , Type} ClassBody: { {ClassBodyDeclaration} } InterfaceBody: { {InterfaceBodyDeclaration} } ClassBodyDeclaration: ; | [static] Block | ModifiersOpt MemberDecl

VoidInterfaceMethodDeclaratorRest: FormalParameters [throws QualifiedIdentifierList] ; ConstructorDeclaratorRest: FormalParameters [throws QualifiedIdentifierList] MethodBody QualifiedIdentifierList: QualifiedIdentifier { , QualifiedIdentifier} FormalParameters: ( [FormalParameter { , FormalParameter}] ) FormalParameter: [final] Type VariableDeclaratorId MethodBody: Block