# Grammar of the Turk/2 Programming Language -- 2003 February 13 Identifier -> ID; QualIdent -> (Identifier ( "." Identifier )* | "this" | "super") ; Literal -> NUM # IntegerLiteral -> FLT # FloatingPointLiteral -> CHR # CharacterLiteral -> STR # StringLiteral -> "true" | "false" # BooleanLiteral -> "null" ; # NullLiteral ConstExpn -> Expression ; Expression -> BoolExpn | CatExpn ; BoolExpn -> BoolTerm ("||" BoolTerm)* ; BoolTerm -> BoolPrim ("&&" BoolPrim)* ; BoolPrim -> CatExpn (RelOp CatExpn)? ; CatExpn -> BitExpn ("#" BitExpn)* ; BitExpn -> BitTerm ("|" BitTerm)* ; BitTerm -> BitFact ("^" BitFact)* ; BitFact -> BitPrim ("&" BitPrim)* ; BitPrim -> MathExpn ("<<" MathExpn | ">>" MathExpn | ">>>" MathExpn) ; MathExpn -> Term ("+" Term | "-" Term)* ; Term -> Primary ("*" Primary | "/" Primary | "%" Primary)* ; Primary -> "!" Primary -> "~" Primary -> "+" Primary -> "-" Primary -> "(" Expression ")" -> QualIdent Arguments -> LeftExpn -> "new" Creator -> ArrayInitializer -> Literal ; Arguments -> "(" (Expression ( "," Expression )*)? ")" ; RelOp -> "==" | "!=" | "<" | ">" | "<=" | ">=" | "instanceof" ; LeftExpn -> QualIdent Selector* ; Selector -> "." Identifier | "[" Expression "]" ; Type -> TypeName ("[" "]")* ; TypeName -> Identifier | BasicType ; BasicType -> "byte" -> "short" -> "int" -> "long" -> "char" -> "float" -> "double" -> "boolean" ; Creator -> TypeName ( ("[" Expression "]")* | Arguments ) ; ArrayInitializer -> "{" VarInitializer ("," VarInitializer)* "}" ; VarInitializer -> ArrayInitializer | Expression ; ParExpression -> "(" Expression ")" ; Block -> "{" LocalVarDecln* Statement* "}" ; LocalVarDecln -> "final"? Type VarDeclor ( "," VarDeclor )* ";" ; Statement -> Block -> "if" ParExpression Statement ("else" Statement)? -> "for" Identifier "=" Expression "," Expression ("," Expression)? "do" Statement -> "while" ParExpression Statement -> "do" Statement "while" ParExpression ";" -> "try" Block ( CatchClause+ | CatchClause* "finally" Block ) -> "switch" ParExpression "{" SwitchBlockGroup* "}" -> "synchronized" ParExpression Block -> "return" Expression? ";" -> "throw" Expression ";" -> "break" # (Identifier)? -> "continue" # (Identifier)? -> LeftExpn "=" Expression ";" -> ";" ; CatchClause -> "catch" "(" FormalParameter ")" Block ; SwitchBlockGroup -> SwitchLabel Statement* ; SwitchLabel -> "case" ConstExpn (".." ConstExpn)? ":" | "default" ":" ; ModifiersOpt -> Modifier* ; Modifier -> "public" -> "protected" -> "private" -> "static" -> "abstract" -> "final" -> "native" -> "synchronized" -> "transient" -> "volatile" -> "strictfp" ; VarDeclor -> Identifier ("=" VarInitializer)? ; CompilationUnit -> ("package" QualIdent ";")? ImportDeclaration* TypeDeclaration* ; ImportDeclaration -> "import" QualIdent ( "." "*" )? ";" ; TypeDeclaration -> ModifiersOpt (ClassDecln | InterfaceDeclaration) -> ";" ; ClassDecln -> ("class" | "type") Identifier ClassOrTypeDecln ; ClassOrTypeDecln -> "=" NewType ";" -> ("extends" Type)? ("implements" TypeList)? "{" ClassBodyDecln* "}" ; TypeList -> Type ( "," Type)* ; NewType -> "{" IdentList "}" -> ConstExpn ".." ConstExpn -> Type ; IdentList -> Identifier ( "," Identifier)* ; ClassBodyDecln -> ModifiersOpt MemberDecl ; MemberDecl -> TypeDeclaration # ClassOrInterfaceDeclaration -> Identifier MethodRest # ConstructorDeclaratorRest -> "void" Identifier MethodRest -> Type Identifier ( MethodRest | "=" VarInitializer ";" | ";") ; MethodRest -> MethodHeader (Block | ";" ) ; MethodHeader -> FormalParams ("throws" QualIdenList)? ; QualIdenList -> QualIdent ("," QualIdent)* ; InterfaceDeclaration -> "interface" Identifier ("extends" TypeList)? "{" InterBodyDecln* "}" ; InterBodyDecln -> ModifiersOpt InterfaceMemberDecl | ";" ; InterfaceMemberDecl -> "void" Identifier MethodHeader ";" -> Type Identifier (MethodHeader | "=" VarInitializer | ) ";" ; FormalParams -> "(" (FormParam ( "," FormParam)*)? ")" ; FormParam -> "final"? Type Identifier ; # ("final"|"static")? # ------------------------------------------------------------------------