Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleGrammar
Class                  ::= "class" ID ("extends" QName)? ("implements" QName ("," QName)*)? "{" (Attribute | Method)* "}". 
Interface              ::= "interface" ID ("extends" QName ("," QName)*)? "{" (MethodDeclaration)* "}".
Attribute              ::= VariableDeclaration (VariableInit)? ";".
VariableDeclaration    ::= Type ID.
Type                   ::= (PrimitiveType | QName) ("[" "]")*.
PrimitiveType          ::= "boolean" | "byte" | "char" | "short" | "int" | "float" | "long" | "double".
Method                 ::= ("override")? MethodDeclaration StatementBlock.  
MethodDeclaration      ::= ID (MethodParameters)? (":" Type)?.
MethodParameters       ::= "(" (VariableDeclaration ("," VariableDeclaration)*)? ")".

...

Code Block
titleExample Class
class Point implements IPoint{
    int x;
    int y;
    
    Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
    
    override getX() : int{
        return this.x;
    }
    
    override getY() : int{
        return this.y;
    }    
}
Code Block
titleExample Interface
interface IPoint {
	getX() : int;
    getY() : int;
}

Statements

Code Block
titleGrammar
Statement              ::= ( StatementBlock | IfStatement | SwitchStatement | WhileStatement | DoWhileStatement | ForStatement | ForEachStatement
                           | VariableStatement | ConstructorStatement | ExpressionStatement | BreakStatement | ContinueStatement | ReturnStatement ).
StatementBlock         ::= "{" (Statement)* "}".
IfStatement            ::= "if" "(" Expression ")" Statement ("else" Statement)?.
SwitchStatement        ::= "switch" "(" Expression ")" "{" ("case" Expression ":" (Statement)*)* ("default" ":" (Statement)*)? "}"
WhileStatement         ::= "while" "(" Expression ")" Statement.
DoWhileStatement       ::= "do" Statement "while" "(" Expression ")" ";".
ForStatement           ::= "for" "(" VariableDeclaration ";" Expression ";" Expression ")" Statement.
ForEachStatement       ::= "for" "(" VariableDeclaration ":" Expression ")" Statement.
VariableStatement      ::= VariableDeclaration VariableInit ";".
ConstructorStatement   ::= ("super" | "this") "(" (ArgsList)? ")" ";".
ExpressionStatement    ::= Expression ";".
BreakStatement         ::= "break" ";".
ContinueStatement      ::= "continue" ";".
ReturnStatement        ::= "return" (Expression)? ";".

...