【问题标题】:SLS language rules notationSLS 语言规则表示法
【发布时间】:2013-10-15 16:21:05
【问题描述】:

我尝试阅读 SLS,但它有一些奇怪的类似 BNF 的符号。任何人都可以澄清这个符号。例如类型章节有以下内容:

Type                 ::= FunctionArgTypes ‘=>’ Type
                       | InfixType [ExistentialClause]
FunctionArgTypes     ::= InfixType
                       | ‘(’ [ ParamType {‘,’ ParamType } ] ‘)’
ExistentialClause    ::= ‘forSome’ ‘{’ ExistentialDcl {semi ExistentialDcl} ‘}’ 
ExistentialDcl       ::= ‘type’ TypeDcl
                       | ‘val’ ValDcl
InfixType            ::= CompoundType {id [nl] CompoundType}
CompoundType         ::= AnnotType {‘with’ AnnotType} [Refinement]
                       | Refinement
AnnotType            ::= SimpleType {Annotation} 
SimpleType           ::= SimpleType TypeArgs
                       | SimpleType ‘#’ id | StableId
                       | Path ‘.’ ‘type’
                       | ‘(’ Types ’)’
TypeArgs             ::= ‘[’ Types ‘]’ 
Types                ::= Type {‘,’ Type}

::=| 这样的符号我很清楚,但 []{} 之间的区别是什么。我也找不到id[nl]RefinmentType 之类的描述。

【问题讨论】:

    标签: scala specifications


    【解决方案1】:

    你是对的,SLS 中使用的符号称为EBNF - 扩展巴科斯-瑙尔形式。它是由 Pascal 的创建者 Niklaus Wirth 开发的,如果我没记错的话,他是 prof 的主管。 Odersky 在他的博士研究中。所有 Scala 语法都在 SLS 的末尾(第 159 页)中进行了描述,您可以在其中找到 TypeRefinmentnl 以及 Scala 中使用的其他内容。

    至于 EBNF 它自己,这里是它的语法的完整表:

    Usage            Notation
    definition       =
    concatenation    ,
    termination      ;
    alternation      |
    option           [ ... ]
    repetition       { ... }
    grouping         ( ... )
    terminal string  " ... "
    terminal string  ' ... '
    comment          (* ... *)
    special sequence ? ... ?
    exception        -
    

    SLS 中的符号稍作修改,即使用::= 代替简单的=,并使用空格代替,

    【讨论】:

      猜你喜欢
      • 2010-09-07
      • 2016-07-11
      • 2013-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 2013-11-07
      相关资源
      最近更新 更多