11  previous  | toc  | next 
Describing the syntax of Java

a concise and universally accepted notation is available
Context-Free Grammars
  • production rules
  • <nonterminal symbol> on the left, and terminal symbols on the right
  • for example, to describe the syntax of identifiers

    Identifier:
    IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
    IdentifierChars:
    JavaLetter IdentifierChars JavaLetterOrDigit
    JavaLetter:
    any Unicode character that is a Java letter
    JavaLetterOrDigit:
    any Unicode character that is a Java letter-or-digit

    Java letter
    is a character for which the method Character.isJavaLetter () returns true
    (Note: Character.isJavaIdentifierStart() in JLS 2.0)
    Java letter-or-digit
    is a character for which the method Character.isJavaLetterOrDigit () returns true
    (Character.isJavaIdentifierPart () in JLS 2.0)

    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
    
    BooleanLiteral: one of
    true false

    NullLiteral:
    null

  • the syntax of Block
    Blocks:
    { BlockStatementsopt }
    BlockStatements:
    BlockStatement
    BlockStatements BlockStatement
    BlockStatement:
    LocalVariableDeclarationStatement
    ClassDeclaration Statement

  • the syntax of Statement
    Statement:
    StatementWithoutTrailingSubstatement
    LabeledStatement
    IfThenStatement
    IfThenElseStatement
    WhileStatement
    ForStatement

  • the syntax of IfThenStatement
    IfThenStatement:
    if ( Expression ) Statement

 11  previous  | toc  | next