[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] / [Samples] / scala.syntax
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Thu Jun 21 16:02:42 PDT 2012

Contents


    Scala Syntax

      MATHS Meta Symbols

    1. #(_)::=zero or more.
    2. O(_)::= (|_), optional.
    3. N(_)::= _ #(_), one or more.

      Lexemes of Scala

    4. upper::= "A".. "Z" | "$" | "_" | Unicode category Lu.
    5. lower::= "a".."z" | Unicode category Ll.
    6. letter::= upper | lower | Unicode categories Lo, Lt, Nl.
    7. digit::= "0" | nonZeroDigit.
    8. nonZeroDigit::= "1".. "9".
    9. octalDigit::= "0" .. "7".

    10. opchar::= all other characters in \u0020-007F and Unicode categories Sm, So except parentheses ([]) and periods.
    11. op::= N(opchar).
    12. varid::= lower idrest.
    13. plainid::= upper idrest | varid| op.
    14. id::= plainid | "\'" stringLit "\.".
    15. idrest::= #(letter | digit) O("_" op).

    16. integerLiteral::= (decimalNumeral | hexNumeral | octalNumeral) O("L" | "l").
    17. decimalNumeral::= "0" | nonZeroDigit #(digit).
    18. hexNumeral::= "0" "x" hexDigit #(hexDigit).
    19. octalNumeral::= "0" octalDigit #(octalDigit).
    20. floatingPointLiteral::=N(digit) "." #(digit) O(exponentPart) O(floatType) | "." N(digit) O(exponentPart) O(floatType) | N(digit) exponentPart O(floatType) | N(digit) O(exponentPart) floatType.

    21. exponentPart::= ("E" | "e") O("+" | "") N(digit).
    22. floatType::= "F" | "f" | "D" | "d".

    23. booleanLiteral::= "true" | "false".
    24. characterLiteral::= "\'" printableChar "\'"| "\'" charEscapeSeq "\'".
    25. stringLiteral::= "\"" #stringElement "\""| "\"\"\"" multiLineChars "\"\"\"".
    26. stringElement::= printableCharNoDoubleQuote| charEscapeSeq.
    27. multiLineChars::= #($)("\"") O("\"") charNoDoubleQuote) #"\"".
    28. symbolLiteral::= "'" plainid.
    29. comment::= "/*" any sequence of characters "*/"| "//" any sequence of characters up to end of line
    30. nl::= new line character.
    31. semicolonOrNl::= ";" | N(nl).

      context-free syntax of Scala

    32. Literal::= O("-") integerLiteral | O("-") floatingPointLiteral | booleanLiteral | characterLiteral | stringLiteral | symbolLiteral | "null".
    33. QualId::= N("." id).
    34. ids::= N("," id)
    35. Path::= StableId| O(id ".") "this".
    36. StableId::= id| Path "." id| O(id ".") "super" O(ClassQualifier) "." id.
    37. ClassQualifier::= "[" id "]".
    38. Type::= FunctionArgTypes "=>" Type | InfixType O(ExistentialClause).
    39. FunctionArgTypes::= InfixType | "(" O( ParamType #("," ParamType )) ")".
    40. ExistentialClause::= "forSome" "{" ExistentialDcl #(semicolonOrNl ExistentialDcl) "}".
    41. ExistentialDcl::= "type" TypeDcl | "val" ValDcl.
    42. InfixType::= CompoundType #(id O(nl) CompoundType).
    43. CompoundType::= AnnotType #("with" AnnotType) O(Refinement) | Refinement.
    44. AnnotType::= SimpleType #(Annotation).

    45. SimpleType::= SimpleType TypeArgs | SimpleType "#" id | StableId | Path "." "type" | "(" Types ")".
    46. TypeArgs::= "[" Types "]".
    47. Types::= Type #("," Type).
    48. Refinement::= O(nl) "{" RefineStat #(semicolonOrNl RefineStat) "}".
    49. RefineStat::= Dcl | "type" TypeDef |.
    50. TypePat::= Type.
    51. Ascription::= ":" InfixType | ":" #N(Annotation) | ":" "_" "*".

    52. Expr::= (Bindings | O("implicit") id | "_") "=>" Expr | Expr1.

    53. Expr1::= "if" "(" Expr ")" #nl Expr O(O(semicolonOrNl) "else" Expr) | "while" "(" Expr ")" #nl Expr | "try" "{" Block "}" O("catch" "{" CaseClauses "}") O("finally" Expr) | "do" Expr O(semicolonOrNl) "while" "(" Expr ")" | "for" ("(" Enumerators ")" | "{" Enumerators "}") #nl ["yield"] Expr | "throw" Expr | "return" O(Expr) | O(SimpleExpr ".") id "=" Expr | SimpleExpr1 ArgumentExprs "=" Expr | PostfixExpr | PostfixExpr Ascription | PostfixExpr "match" "{" CaseClauses "}".
    54. PostfixExpr::= InfixExpr O(id O(nl)).
    55. InfixExpr::= PrefixExpr | InfixExpr id O(nl) InfixExpr
    56. PrefixExpr::= O("-" | "+" | "~" | "!") SimpleExpr
    57. SimpleExpr::= "new" (ClassTemplate | TemplateBody) | BlockExpr | SimpleExpr1 O("_").
    58. SimpleExpr1::= Literal | Path | "_" | "(" O(Exprs) ")" | SimpleExpr "." id | SimpleExpr TypeArgs | SimpleExpr1 ArgumentExprs| XmlExpr.
    59. Exprs::= Expr #("," Expr).
    60. ArgumentExprs::= "(" O(Exprs) ")" | "(" O(Exprs ",") PostfixExpr ":" "_" "*" ")" | O(nl) BlockExpr
    61. BlockExpr::= "{" CaseClauses "}" | "{" Block "}"
    62. Block::= #(BlockStat semicolonOrNl) O(ResultExpr).
    63. BlockStat::= Import | #Annotation O("implicit" | "lazy") Def | #Annotation #LocalModifier TmplDef | Expr1 |.
    64. ResultExpr::= Expr1 | (Bindings | (O("implicit") id | "_") ":" CompoundType) "=>" Block.
    65. Enumerators::= Generator #(semicolonOrNl Enumerator).
    66. Enumerator::= Generator | Guard | "val" Pattern1 "=" Expr.
    67. Generator::= Pattern1 "<" Expr O(Guard).
    68. CaseClauses::= N(CaseClause).
    69. CaseClause::= "case" Pattern $)(Guard) "=>" Block.
    70. Guard::= "if" PostfixExpr.

    71. Pattern::= Pattern1 #( "|" Pattern1 ).
    72. Pattern1::= varid ":" TypePat | "_" ":" TypePat | Pattern2.
    73. Pattern2::= varid O("@" Pattern3) | Pattern3.

    74. Pattern3::= SimplePattern | SimplePattern #( id O(nl) SimplePattern).
    75. SimplePattern::= "_" | varid | Literal | StableId | StableId "(" O(Patterns) ")" | StableId "(" O(Patterns ",") O(varid "@") "_" "*" ")" | "(" O(Patterns) ")" | XmlPattern.
    76. Patterns::= Pattern ["," Patterns] | "_" "*".
    77. TypeParamClause::= "[" VariantTypeParam #("," VariantTypeParam) "]".
    78. FunTypeParamClause::= "[" TypeParam #("," TypeParam) "]".
    79. VariantTypeParam::= #Annotation O("+" | "-") TypeParam.
    80. TypeParam::= (id | "_") O(TypeParamClause)O(">:" Type) #O("<:" Type) #("<%" Type) #(":" Type).
    81. ParamClauses::= #(ParamClause) O(O(nl) "(" "implicit" Params ")").
    82. ParamClause::= O(nl) "(" O(Params) ")".
    83. Params::= Param #("," Param).
    84. Param::= #Annotation id O(":" ParamType) O("=" Expr).
    85. ParamType::= Type | "=>" Type | Type "*".

    86. ClassParamClauses::= #ClassParamClause O(O(nl) "(" "implicit" ClassParams ")").
    87. ClassParamClause::= O(nl) "(" O(ClassParams) ")".
    88. ClassParams::= ClassParam #("" ClassParam).
    89. ClassParam::= #Annotation O(#(Modifier) ("val" | "var")) id ":" ParamType O("=" Expr).
    90. Bindings::= "(" Binding #("," Binding) ")".
    91. Binding::= (id | "_") O(":" Type).

    92. Modifier::= LocalModifier | AccessModifier | "override".
    93. LocalModifier::= "abstract" | "final" | "sealed" | "implicit" | "lazy".
    94. AccessModifier::= ("private" | "protected") O(AccessQualifier).
    95. AccessQualifier::= "[" (id | "this") "]"
    96. Annotation::= "@" SimpleType #(ArgumentExprs).
    97. ConstrAnnotation::= "@" SimpleType ArgumentExprs.
    98. NameValuePair::= "val" id "=" PrefixExpr.

    99. TemplateBody::= O(nl) "{" #O(SelfType) TemplateStat #(semicolonOrNl TemplateStat) "}".
    100. TemplateStat::= Import | #(Annotation O(nl) #Modifier Def | #(Annotation O(nl)) #Modifier Dcl | Expr |.
    101. SelfType::= id O(":" Type) "=>" | "this" ":" Type "=>".
    102. Import::= "import" ImportExpr #("," ImportExpr).
    103. ImportExpr::= StableId "." (id | "_" | ImportSelectors).
    104. ImportSelectors::= "{" #(ImportSelector ",") (ImportSelector | "_") "}".
    105. ImportSelector::= id O("=>" id | "=>" "_").

    106. Dcl::= "val" ValDcl | "var" VarDcl | "def" FunDcl | "type" #nl TypeDcl.
    107. ValDcl::= ids ":" Type.
    108. VarDcl::= ids ":" Type.
    109. FunDcl::= FunSig O(":" Type).
    110. FunSig::= id O(FunTypeParamClause) ParamClauses.
    111. TypeDcl::= id O(TypeParamClause) O(">:" Type) O("<:" Type).
    112. PatVarDef::= "val" PatDef | "var" VarDef.
    113. Def::= PatVarDef | "def" FunDef | "type" #nl TypeDef | TmplDef.
    114. PatDef::= Pattern2 #("," Pattern2# O(":" Type) "=" Expr.
    115. VarDef::= PatDef | ids ":" Type "=" "_".
    116. FunDef::= FunSig O(":" Type) "=" Expr | FunSig O(nl) "{" Block "}" | "this" ParamClause ParamClauses ("=" ConstrExpr | O(nl) ConstrBlock).
    117. TypeDef::= id O(TypeParamClause) "=" Type.
    118. TmplDef::= O("case") "class" ClassDef | O("case") "object" ObjectDef | "trait" TraitDef.

    119. ClassDef::= id O(TypeParamClause) #ConstrAnnotation# O(AccessModifier) ClassParamClauses ClassTemplateOpt.

    120. TraitDef::= id O(TypeParamClause) TraitTemplateOpt.

    121. ObjectDef::= id ClassTemplateOpt

    122. ClassTemplateOpt::= "extends" ClassTemplate | O(O("extends") TemplateBody).
    123. TraitTemplateOpt::= "extends" TraitTemplate | O(O("extends") TemplateBody).
    124. ClassTemplate::= O(EarlyDefs) ClassParents O(TemplateBody).
    125. TraitTemplate::= O(EarlyDefs) TraitParents O(TemplateBody).
    126. ClassParents::= Constr #("with" AnnotType).
    127. TraitParents::= AnnotType #("with" AnnotType).
    128. Constr::= AnnotType #(ArgumentExprs).
    129. EarlyDefs::= "{" O(EarlyDef #(semicolonOrNl EarlyDef) "}" "with"
    130. EarlyDef::= #(Annotation O(nl)) #(Modifier) PatVarDef.
    131. ConstrExpr::= SelfInvocation | ConstrBlock.
    132. ConstrBlock::= "{" SelfInvocation #(semicolonOrNl BlockStat) "}".
    133. SelfInvocation::= "this" ArgumentExprs #(ArgumentExprs).

    134. TopStatSeq::= TopStat #(semicolonOrNl TopStat).
    135. TopStat::= #(Annotation O(nl)) #Modifier TmplDef | Import | Packaging | PackageObject |.
    136. Packaging::= "package" QualId O(nl) "{" TopStatSeq "}".
    137. PackageObject::= "package" "object" ObjectDef.
    138. CompilationUnit::= #("package" QualId semicolonOrNl) TopStatSeq.

    . . . . . . . . . ( end of section Scala Syntax) <<Contents | End>>

End