BNF for objects.oo

NON-TERMINALS

CompilationUnit ::= ClassDeclaration ( ClassDeclaration )* <EOF>
ClassDeclaration ::= ( "abstract" )? "class" <IDENTIFIER> ( "extends" <IDENTIFIER> )? "{" ( ClassBodyDeclaration )* "}"
ClassBodyDeclaration ::= ( ConstructorDeclaration | MethodDeclaration | FieldDeclaration )
FieldDeclaration ::= Type <IDENTIFIER> ";"
MethodDeclaration ::= ( ( "static" | "abstract" ) )* ResultType <IDENTIFIER> FormalParameters ( ( Block | ";" ) )
FormalParameters ::= "(" ( FormalParameter ( "," FormalParameter )* )? ")"
FormalParameter ::= CallingConvention Type <IDENTIFIER>
CallingConvention ::= ( "val" | "need" )
ConstructorDeclaration ::= <IDENTIFIER> FormalParameters "{" ( ExplicitConstructorInvocation )? ( BlockStatement )* "}"
ExplicitConstructorInvocation ::= "super" Arguments ";"
Type ::= ( ( PrimitiveType | <IDENTIFIER> ) )
PrimitiveType ::= ( "boolean" | "int" | "float" )
ResultType ::= ( "void" | Type )
Expression ::= ConditionalExpression
ConditionalExpression ::= ConditionalOrExpression ( "?" Expression ":" ConditionalExpression )?
ConditionalOrExpression ::= ConditionalAndExpression ( "||" ConditionalAndExpression )*
ConditionalAndExpression ::= InclusiveOrExpression ( "&&" InclusiveOrExpression )*
InclusiveOrExpression ::= ExclusiveOrExpression ( "|" ExclusiveOrExpression )*
ExclusiveOrExpression ::= AndExpression ( "^" AndExpression )*
AndExpression ::= EqualityExpression ( "&" EqualityExpression )*
EqualityExpression ::= InstanceOfExpression ( ( ( "==" | "!=" ) ) InstanceOfExpression )*
InstanceOfExpression ::= RelationalExpression ( "instanceof" Type )?
RelationalExpression ::= ShiftExpression ( ( ( "<" | ">" | "<=" | ">=" ) ) ShiftExpression )?
ShiftExpression ::= AdditiveExpression ( ( ( "<<" | ">>" | ">>>" ) ) AdditiveExpression )*
AdditiveExpression ::= MultiplicativeExpression ( ( ( "+" | "-" ) ) MultiplicativeExpression )*
MultiplicativeExpression ::= UnaryExpression ( ( ( "*" | "/" | "%" ) ) UnaryExpression )*
UnaryExpression ::= ( ( ( "+" | "-" ) ) UnaryExpression | UnaryExpressionNotPlusMinus )
UnaryExpressionNotPlusMinus ::= ( ( ( "~" | "!" ) ) UnaryExpression | CastExpression | PrimaryExpression )
CastExpression ::= "(" <IDENTIFIER> ")" UnaryExpressionNotPlusMinus
PrimaryExpression ::= ( Literal | "(" Expression ")" | StaticMethodCall | VirtualMethodCall | FieldAccess | <IDENTIFIER> | AllocationExpression )
VirtualMethodCall ::= <IDENTIFIER> "." <IDENTIFIER> Arguments
StaticMethodCall ::= <IDENTIFIER> Arguments
FieldAccess ::= <IDENTIFIER> "." <IDENTIFIER>
Literal ::= ( <INTEGER_LITERAL> | <FLOATING_POINT_LITERAL> | BooleanLiteral | NullLiteral )
BooleanLiteral ::= ( "true" | "false" )
NullLiteral ::= "null"
Arguments ::= "(" ( ArgumentList )? ")"
ArgumentList ::= Expression ( "," Expression )*
AllocationExpression ::= "new" <IDENTIFIER> Arguments
Statement ::= ( Block | EmptyStatement | StatementExpression ";" | SwitchStatement | IfStatement | WhileStatement | BreakStatement | ContinueStatement | ReturnStatement | PrintStatement )
PrintStatement ::= "print" "(" Expression ")"
Block ::= "{" ( BlockStatement )* "}"
BlockStatement ::= ( LocalVariableDeclaration ";" | Statement )
LocalVariableDeclaration ::= Type <IDENTIFIER> "=" Expression
EmptyStatement ::= ";"
StatementExpression ::= <IDENTIFIER> "=" Expression
SwitchStatement ::= "switch" "(" Expression ")" "{" ( SwitchLabel ( BlockStatement )* )* "}"
SwitchLabel ::= ( "case" Expression ":" | "default" ":" )
IfStatement ::= "if" "(" Expression ")" Statement ( "else" Statement )?
WhileStatement ::= "while" "(" Expression ")" Statement
BreakStatement ::= "break" ";"
ContinueStatement ::= "continue" ";"
ReturnStatement ::= "return" ( Expression )? ";"