Previous Up

Ocaml grammar overview

This appendix contains all grammar rules from this manual, including those for the toplevel and the debugger.

Page navigation


6.1  Lexical conventions

Identifiers

ident::= ( letter ∣  _ ) { letter ∣  0 … 9 ∣  _ ∣  ' }  
 
capitalized-ident::= (A … Z) { letter ∣  0 … 9 ∣  _ ∣  ' }  
 
lowercase-ident::= (a … z ∣  _) { letter ∣  0 … 9 ∣  _ ∣  ' }  
 
letter::= A … Z ∣  a … z

Integer literals

integer-literal::= [-] (09) { 09 ∣  _ }  
  [-] (0x∣ 0X) (09∣ AF∣ af) { 09∣ AF∣ af∣ _ }  
  [-] (0o∣ 0O) (07) { 07∣ _ }  
  [-] (0b∣ 0B) (01) { 01∣ _ }
 
extension for Extension literals:
  [-] (09) { 09 ∣  _ }[gz∣ GZ]  
  [-] (0x∣ 0X) (09∣ AF∣ af) { 09∣ AF∣ af∣ _ } [gz∣ GZ]  
  [-] (0o∣ 0O) (07) { 07∣ _ } [gz∣ GZ]  
  [-] (0b∣ 0B) (01) { 01∣ _ } [gz∣ GZ]  

Floating-point literals

float-literal::= [-] (09) { 09∣ _ } [. { 09∣ _ }] [(e∣ E) [+∣ -] (09) { 09∣ _ }]  
  [-] (0x∣ 0X) (09∣ AF∣ af) { 09∣ AF∣ af∣ _ } [. { 09∣ AF∣ af∣ _ } [(p∣ P) [+∣ -] (09) { 09∣ _ }]
 
extension for Extension literals:
  [-] (09) { 09∣ _ } [. { 09∣ _ }] [(e∣ E) [+∣ -] (09) { 09∣ _ }] [gz∣ GZ]  
  [-] (0x∣ 0X) (09∣ AF∣ af) { 09∣ AF∣ af∣ _ } [. { 09∣ AF∣ af∣ _ } [(p∣ P) [+∣ -] (09) { 09∣ _ }] [gz∣ GZ]  

Character literals

char-literal::= ' regular-char '  
  ' escape-sequence '  
 
escape-sequence::= \ ( \ ∣  " ∣  ' ∣  n ∣  t ∣  b ∣  r ∣  space )  
  \ (09) (09) (09)  
  \x (09∣ AF∣ af) (09∣ AF∣ af)  
  \o (03) (07) (07)

String literals

string-literal::= " { string-character } "  
 
extension for Quoted strings:
   { quoted-string-id |  ........ |  quoted-string-id }  
 
string-character::= regular-string-char  
  escape-sequence  
  \ newline  { space ∣  tab }

Naming labels

label-name::= lowercase-ident  
 
label::= ~ label-name :  
 
optlabel::= ? label-name :

Prefix and infix symbols

infix-symbol::= (= ∣  < ∣  > ∣  @ ∣  ^ ∣  | ∣  & ∣  + ∣  - ∣  * ∣  / ∣  $ ∣  %) { operator-char }  
  # { operator-char }+  
 
extension for Extension operators:
  # {operator-chars#   {operator-char | #}  
 
prefix-symbol::= ! { operator-char }  
  (? ∣  ~) { operator-char }+  
 
operator-char::= ! ∣  $ ∣  % ∣  & ∣  * ∣  + ∣  - ∣  . ∣  / ∣  : ∣  < ∣  = ∣  > ∣  ? ∣  @ ∣  ^ ∣  | ∣  ~

Line number directives

linenum-directive::= # {0 … 9}+  
  # {0 … 9}+ " { string-character } "

6.3  Names

Naming objects

value-name::= lowercase-ident  
  ( operator-name )  
 
operator-name::= prefix-symbol ∣  infix-op  
 
infix-op::= infix-symbol  
  * ∣  + ∣  - ∣  -. ∣  = ∣  != ∣  < ∣  > ∣  or ∣  || ∣  & ∣  && ∣  :=  
  mod ∣  land ∣  lor ∣  lxor ∣  lsl ∣  lsr ∣  asr  
 
constr-name::= capitalized-ident  
 
tag-name::= capitalized-ident  
 
typeconstr-name::= lowercase-ident  
 
field-name::= lowercase-ident  
 
module-name::= capitalized-ident  
 
modtype-name::= ident  
 
class-name::= lowercase-ident  
 
inst-var-name::= lowercase-ident  
 
method-name::= lowercase-ident

Referring to named objects

value-path::=module-path . ]  value-name  
 
constr::=module-path . ]  constr-name  
 
typeconstr::=extended-module-path . ]  typeconstr-name  
 
field::=module-path . ]  field-name  
 
modtype-path::=extended-module-path . ]  modtype-name  
 
class-path::=module-path . ]  class-name  
 
classtype-path::=extended-module-path . ]  class-name  
 
module-path::= module-name  { . module-name }  
 
extended-module-path::= extended-module-name  { . extended-module-name }  
 
extended-module-name::= module-name  { ( extended-module-path ) }

6.4  Type expressions

typexpr::= ' ident  
  _  
  ( typexpr )  
  [[?]label-name:]  typexpr ->  typexpr  
  typexpr  { * typexpr }+  
  typeconstr  
  typexpr  typeconstr  
  ( typexpr  { , typexpr } )  typeconstr  
  typexpr as '  ident  
  polymorphic-variant-type  
  < [..>  
  < method-type  { ; method-type }  [; ∣  ; ..>  
  # class-path  
  typexpr #  class-path  
  ( typexpr  { , typexpr } ) #  class-path  
 
extension for First-class modules:
  (module package-type)  
 
extension for Attributes:
  typexpr  attribute  
 
extension for Extension nodes:
  extension  
 
poly-typexpr::= typexpr  
  { ' ident }+ .  typexpr  
 
method-type::= method-name :  poly-typexpr

Polymorphic variant types

polymorphic-variant-type::= [ tag-spec-first  { | tag-spec } ]  
  [> [ tag-spec ]  { | tag-spec } ]  
  [< [|tag-spec-full  { | tag-spec-full }  [ > { `tag-name }+ ] ]  
 
tag-spec-first::= `tag-name  [ of typexpr ]  
  [ typexpr ] |  tag-spec  
 
tag-spec::= `tag-name  [ of typexpr ]  
  typexpr  
 
tag-spec-full::= `tag-name  [ of [&typexpr  { & typexpr } ]  
  typexpr

6.5  Constants

constant::= integer-literal  
  float-literal  
  char-literal  
  string-literal  
  constr  
  false  
  true  
  ()  
  begin end  
  []  
  [||]  
  `tag-name
 
extension for Integer literals for types int32, int64 and nativeint:
  int32-literal  
  int64-literal  
  nativeint-literal  

6.6  Patterns

pattern::= value-name  
  _  
  constant  
  pattern as  value-name  
  ( pattern )  
  ( pattern :  typexpr )  
  pattern |  pattern  
  constr  pattern  
  `tag-name  pattern  
  #typeconstr  
  pattern  { , pattern }+  
  { field  [: typexpr] =  pattern { ; field  [: typexpr] =  pattern }  [ ; ] }  
  [ pattern  { ; pattern }  [ ; ] ]  
  pattern ::  pattern  
  [| pattern  { ; pattern }  [ ; ] |]  
  char-literal ..  char-literal
 
extension for Lazy patterns:
  lazy pattern
 
extension for Record and object notations:
  { field  [= pattern]  { ; field  [= pattern] }  [; _ ] [;}  
 
extension for First-class modules:
  (module module-name  [: package-type])  
 
extension for Attributes:
  pattern  attribute  
 
extension for Extension nodes:
  extension  
 
extension for Exception cases in pattern matching:
  exception pattern  

6.7  Expressions

expr::= value-path  
  constant  
  ( expr )  
  begin expr end  
  ( expr :  typexpr )  
  expr  {, expr}+  
  constr  expr  
  `tag-name  expr  
  expr ::  expr  
  [ expr  { ; expr }  [;]  
  [| expr  { ; expr }  [;|]  
  { field  [: typexpr] =  expr { ; field  [: typexpr] =  expr }  [;}  
  { expr with  field  [: typexpr] =  expr { ; field  [: typexpr] =  expr }  [;}  
  expr  { argument }+  
  prefix-symbol  expr  
  - expr  
  -. expr  
  expr  infix-op  expr  
  expr .  field  
  expr .  field <-  expr  
  expr .(  expr )  
  expr .(  expr ) <-  expr  
  expr .[  expr ]  
  expr .[  expr ] <-  expr  
  if expr then  expr  [ else expr ]  
  while expr do  expr done  
  for value-name =  expr  ( to ∣  downto ) expr do  expr done  
  expr ;  expr  
  match expr with  pattern-matching  
  function pattern-matching  
  fun { parameter }+  [when expr] : typexpr ] ->  expr  
  try expr with  pattern-matching  
  let [reclet-binding  { and let-binding } in  expr  
  new class-path  
  object class-body end  
  expr #  method-name  
  inst-var-name  
  inst-var-name <-  expr  
  ( expr :>  typexpr )  
  ( expr :  typexpr :>  typexpr )  
  {< [ inst-var-name =  expr  { ; inst-var-name =  expr }  [;] ] >}  
  assert expr  
  lazy expr  
  let module module-name  { ( module-name :  module-type ) }  [ : module-type ]  =  module-expr in  expr 
 
extension for Method definition:
  inst-var-name <-  expr  
  {< [ inst-var-name =  expr  { ; inst-var-name =  expr }  [;] ] >}
 
extension for Local opens:
  let open module-path in  expr  
  module-path .(  expr )
 
extension for Local opens for delimited expressions:
  module-path .[  expr ]  
  module-path .[|  expr |]  
  module-path .{  expr }  
  module-path .{<  expr >}
 
extension for Record and object notations:
  { field  [= expr]  { ; field  [= expr] }  [;}  
  { expr with  field  [= expr]  { ; field  [= expr] }  [;}  
  { < expr with  field  [= expr]  { ; field  [= expr] }  [;> }
 
extension for First-class modules:
  (module module-expr  [: package-type])  
 
extension for Overriding in open statements:
  let open! module-path in  expr
 
extension for Syntax for Bigarray access:
  expr .{  expr  { , expr } }  
  expr .{  expr  { , expr } } <-  expr
 
extension for Attributes:
  expr  attribute  
 
extension for Extension nodes:
  extension  
 
argument::= expr  
  ~ label-name  
  ~ label-name :  expr  
  ? label-name  
  ? label-name :  expr  
 
pattern-matching::=| ] pattern  [when expr->  expr  { | pattern  [when expr->  expr }  
 
let-binding::= pattern =  expr  
  value-name  { parameter }  [: typexpr]  [:> typexpr=  expr  
 
extension for Explicit polymorphic type annotations:
  value-name :  poly-typexpr =  expr
 
extension for Polymorphic syntax:
  value-name : type  { typeconstr-name }+ .  typexpr =  expr  
 
parameter::= pattern  
  ~ label-name  
  ~ ( label-name  [: typexpr)  
  ~ label-name :  pattern  
  ? label-name  
  ? ( label-name  [: typexpr]  [= expr)  
  ? label-name :  pattern  
  ? label-name : (  pattern  [: typexpr]  [= expr)
 
extension for Locally abstract types:
  ( type {typeconstr-name}+ )

6.8  Type and exception definitions

6.8.1  Type definitions

type-definition::= type [nonrec] typedef  { and typedef }  
 
typedef::= [type-params]  typeconstr-name  type-information  
 
extension for Attributes:
  typedef  item-attribute  
 
type-information::= [type-equation]  [type-representation]  { type-constraint }  
 
type-equation::= = typexpr  
 
extension for Private type abbreviations:
  = private typexpr
 
extension for Private row types:
  = private typexpr
 
type-representation::= = [|constr-decl  { | constr-decl }  
  = record-decl  
 
extension for Private variant and record types:
  = private [ | ] constr-decl  { | constr-decl }  
  = private record-decl
 
extension for Extensible variant types:
  = ..  
 
type-params::= type-param  
  ( type-param  { , type-param } )  
 
type-param::= [variance'  ident  
 
extension for Generalized algebraic datatypes:
  [variance_
 
variance::= +  
  -  
 
record-decl::= { field-decl  { ; field-decl }  [;}  
 
constr-decl::= (constr-name ∣  () ∣  [] ∣  (::)) [ of constr-args ]  
 
redefinition for Attributes:
constr-decl::= (constr-name ∣  (){attribute} [ of constr-args ]  {attribute}  
 
extension for Generalized algebraic datatypes:
  constr-name :  [ constr-args -> ]  typexpr  
 
constr-args::= typexpr  { * typexpr }  
 
extension for Inline records:
  record-decl  
 
field-decl::= [mutablefield-name :  poly-typexpr  
 
redefinition for Attributes:
field-decl::= [mutablefield-name {attribute} :  poly-typexpr  {attribute}  
 
type-constraint::= constraint ' ident =  typexpr

6.8.2  Exception definitions

exception-definition::= exception constr-name  [ of typexpr  { * typexpr } ]  
  exception constr-name =  constr
 
redefinition for Attributes:
exception-definition::= exception constr-name  { attribute }  [ of typexpr  { * typexpr } ]  
  exception constr-name =  constr  

6.9  Classes

6.9.1  Class types

class-type::= [[?]label-name:]  typexpr ->  class-type  
    class-body-type  
 
extension for Attributes:
  class-type  attribute  
 
extension for Extension nodes:
  extension  
 
class-body-type::= object [( typexpr )]  {class-field-specend  
   [[ typexpr  {, typexpr]]  classtype-path  
 
class-field-spec::= inherit class-body-type  
   val [mutable] [virtualinst-var-name :  typexpr  
   val virtual mutable inst-var-name :  typexpr  
   method [private] [virtualmethod-name :  poly-typexpr  
   method virtual private method-name :  poly-typexpr  
   constraint typexpr =  typexpr
 
extension for Attributes:
  class-field-spec  item-attribute  
 
extension for Attributes:
  floating-attribute  
 
extension for Extension nodes:
  item-extension  

6.9.2  Class expressions

class-expr::= class-path  
   [ typexpr  {, typexpr]  class-path  
   ( class-expr )  
   ( class-expr :  class-type )  
   class-expr  {argument}+  
   fun {parameter}+ ->  class-expr  
   let [reclet-binding  {and let-bindingin  class-expr  
   object class-body end  
 
extension for Attributes:
  class-expr  attribute  
 
extension for Extension nodes:
  extension  
 
class-field::= inherit class-expr  [as lowercase-ident]  
   val [mutableinst-var-name  [: typexpr=  expr  
   val [mutablevirtual inst-var-name :  typexpr  
   val virtual mutable inst-var-name :  typexpr  
   method [privatemethod-name  {parameter}  [: typexpr=  expr  
   method [privatemethod-name :  poly-typexpr =  expr  
   method [privatevirtual method-name :  poly-typexpr  
   method virtual private method-name :  poly-typexpr  
   constraint typexpr =  typexpr  
   initializer expr
 
extension for Polymorphic syntax:
  method [privatemethod-name : type  { typeconstr-name }+ .  typexpr =  expr  
  method! [privatemethod-name : type  { typeconstr-name }+ .  typexpr =  expr
 
extension for Explicit overriding in class definitions:
   inherit! class-expr  [as lowercase-ident]  
   val! [mutableinst-var-name  [: typexpr=  expr  
   method! [privatemethod-name  {parameter}  [: typexpr=  expr  
   method! [privatemethod-name :  poly-typexpr =  expr
 
extension for Attributes:
  class-field  item-attribute  
 
extension for Attributes:
  floating-attribute  
 
extension for Extension nodes:
  item-extension  

Class body

class-body::=  [( pattern  [: typexpr)]  { class-field }

Method definition

expr::= …  
  inst-var-name <-  expr  
  {< [ inst-var-name =  expr  { ; inst-var-name =  expr }  [;] ] >}

6.9.3  Class definitions

class-definition::= class class-binding  { and class-binding }  
 
class-binding::= [virtual] [[ type-parameters ]]  class-name  {parameter}  [: class-type]  =  class-expr  
 
extension for Attributes:
  class-binding  item-attribute  
 
type-parameters::= ' ident  { , ' ident }

6.9.4  Class specifications

class-specification::= class class-spec  { and class-spec }  
 
class-spec::= [virtual] [[ type-parameters ]]  class-name :  class-type
 
extension for Attributes:
  class-spec  item-attribute  

6.9.5  Class type definitions

classtype-definition::= class type classtype-def  { and classtype-def }  
 
classtype-def::= [virtual] [[ type-parameters ]]  class-name =  class-body-type
 
extension for Attributes:
  classtype-def  item-attribute  

6.10  Module types (module specifications)

module-type::= modtype-path  
  sig { specification  [;;] } end  
  functor ( module-name :  module-type ) ->  module-type  
  module-type ->  module-type  
  module-type with  mod-constraint  { and mod-constraint }  
  ( module-type )  
 
extension for Recovering the type of a module:
  module type of module-expr
 
extension for Attributes:
  module-type  attribute  
 
extension for Extension nodes:
  extension  
 
extension for Generative functors:
  functor () -> module-type  
 
mod-constraint::= type [type-params]  typeconstr  type-equation  type-constraint }  
  module module-path =  extended-module-path  
 
extension for Substituting inside a signature:
  type [type-params]  typeconstr-name :=  typexpr  
  module module-name :=  extended-module-path
 
specification::= val value-name :  typexpr  
  external value-name :  typexpr =  external-declaration  
  type-definition  
  exception constr-decl  
  class-specification  
  classtype-definition  
  module module-name :  module-type  
  module module-name  { ( module-name :  module-type ) } :  module-type  
  module type modtype-name  
  module type modtype-name =  module-type  
  open module-path  
  include module-type
 
redefinition for Attributes:
specification::= val value-name :  typexpr  { item-attribute }  
  external value-name :  typexpr =  external-declaration  { item-attribute }  
  type-definition  
  exception constr-decl  { item-attribute }  
  class-specification  
  classtype-definition  
  module module-name :  module-type  { item-attribute }  
  module module-name  { ( module-name :  module-type ) } :  module-type  { item-attribute }  
  module type modtype-name  { item-attribute }  
  module type modtype-name =  module-type  { item-attribute }  
  open module-path  { item-attribute }  
  include module-type  { item-attribute }  
 
extension for Recursive modules:
  module rec module-name :  module-type  { and module-name:  module-type }
 
extension for Type-level module aliases:
  module module-name =  module-path
 
extension for Overriding in open statements:
   open! module-path  
 
extension for Attributes:
  floating-attribute  
 
extension for Extension nodes:
  item-extension  
 
extension for Extensible variant types:
  type [type-params]  typeconstr  type-extension-spec  
 
extension for Generative functors:
  module module-name  { ( module-name :  module-type ) ∣  () } : module-type  

6.11  Module expressions (module implementations)

module-expr::= module-path  
  struct [ module-items ] end  
  functor ( module-name :  module-type ) ->  module-expr  
  module-expr (  module-expr )  
  ( module-expr )  
  ( module-expr :  module-type )  
 
extension for First-class modules:
  (val expr  [: package-type])  
 
extension for Attributes:
  module-expr  attribute  
 
extension for Extension nodes:
  extension  
 
extension for Generative functors:
  functor () -> module-expr  
  module-expr ()  
 
module-items::= {;;} ( definition ∣  expr )  { {;;} ( definition ∣  ;; expr) }  {;;}  
 
redefinition for Attributes:
module-items::= [;;] ( definition ∣  expr  { item-attribute } )  { [;;definition ∣  ;; expr  { item-attribute } }  [;;]  
 
definition::= let [reclet-binding  { and let-binding }  
  external value-name :  typexpr =  external-declaration  
  type-definition  
  exception-definition  
  class-definition  
  classtype-definition  
  module module-name  { ( module-name :  module-type ) }  [ : module-type ]  =  module-expr  
  module type modtype-name =  module-type  
  open module-path  
  include module-expr
 
redefinition for Attributes:
definition::= let [reclet-binding  { and let-binding }  
  external value-name :  typexpr =  external-declaration  { item-attribute }  
  type-definition  
  exception-definition  { item-attribute }  
  class-definition  
  classtype-definition  
  module module-name  { ( module-name :  module-type ) }  [ : module-type ]  =  module-expr  { item-attribute }  
  module type modtype-name =  module-type  { item-attribute }  
  open module-path  { item-attribute }  
  include module-expr  { item-attribute }  
  module rec module-name :  module-type =   module-expr  { item-attribute }   { and module-name :  module-type =  module-expr   { item-attribute } }  
 
extension for Recursive modules:
  module rec module-name :  module-type =  module-expr   { and module-name :  module-type =  module-expr }  
 
extension for Overriding in open statements:
   open! module-path  
 
extension for Attributes:
  floating-attribute  
 
extension for Extension nodes:
  item-extension  
 
extension for Extensible variant types:
  type [type-params]  typeconstr  type-extension-def  
 
extension for Generative functors:
  module module-name  { ( module-name :  module-type ) ∣  () } [ : module-type ]  =  module-expr  

6.12  Compilation units

unit-interface::= { specification  [;;] }  
 
unit-implementation::= [ module-items ]

Chapter 7  Language extensions

7.1  Integer literals for types int32, int64 and nativeint

constant::= ...  
  int32-literal  
  int64-literal  
  nativeint-literal  
 
int32-literal::= integer-literal l  
 
int64-literal::= integer-literal L  
 
nativeint-literal::= integer-literal n

7.3  Lazy patterns

pattern::= ...  
  lazy pattern

7.4  Recursive modules

definition::= ...  
  module rec module-name :  module-type =  module-expr   { and module-name :  module-type =  module-expr }  
 
specification::= ...  
  module rec module-name :  module-type  { and module-name:  module-type }

7.5  Private types

7.5.1  Private variant and record types

type-representation::= ...  
  = private [ | ] constr-decl  { | constr-decl }  
  = private record-decl

7.5.2  Private type abbreviations

type-equation::= ...  
  = private typexpr

7.5.3  Private row types

type-equation::= ...  
  = private typexpr

7.6  Local opens

expr::= ...  
  let open module-path in  expr  
  module-path .(  expr )
Local opens for delimited expressions
expr::= ...  
  module-path .[  expr ]  
  module-path .[|  expr |]  
  module-path .{  expr }  
  module-path .{<  expr >}

7.7  Record and object notations

pattern::= ...  
  { field  [= pattern]  { ; field  [= pattern] }  [; _ ] [;}  
 
expr::= ...  
  { field  [= expr]  { ; field  [= expr] }  [;}  
  { expr with  field  [= expr]  { ; field  [= expr] }  [;}  
  { < expr with  field  [= expr]  { ; field  [= expr] }  [;> }

7.8  Explicit polymorphic type annotations

let-binding::= ...  
  value-name :  poly-typexpr =  expr

7.9  Locally abstract types

parameter::= ...  
  ( type {typeconstr-name}+ )
Polymorphic syntax
let-binding::= ...  
  value-name : type  { typeconstr-name }+ .  typexpr =  expr  
 
class-field::= ...  
  method [privatemethod-name : type  { typeconstr-name }+ .  typexpr =  expr  
  method! [privatemethod-name : type  { typeconstr-name }+ .  typexpr =  expr

7.10  First-class modules

typexpr::= ...  
  (module package-type)  
 
module-expr::= ...  
  (val expr  [: package-type])  
 
expr::= ...  
  (module module-expr  [: package-type])  
 
pattern::= ...  
  (module module-name  [: package-type])  
 
package-type::= modtype-path  
  modtype-path with  package-constraint  { and package-constraint }  
 
package-constraint::= type typeconstr =  typexpr  
 

7.11  Recovering the type of a module

module-type::= ...  
  module type of module-expr

7.12  Substituting inside a signature

mod-constraint::= ...  
  type [type-params]  typeconstr-name :=  typexpr  
  module module-name :=  extended-module-path

7.13  Type-level module aliases

specification::= ...  
  module module-name =  module-path

7.14  Explicit overriding in class definitions

class-field::= ...  
   inherit! class-expr  [as lowercase-ident]  
   val! [mutableinst-var-name  [: typexpr=  expr  
   method! [privatemethod-name  {parameter}  [: typexpr=  expr  
   method! [privatemethod-name :  poly-typexpr =  expr

7.15  Overriding in open statements

definition::= ...  
   open! module-path  
 
specification::= ...  
   open! module-path  
 
expr::= ...  
  let open! module-path in  expr

7.16  Generalized algebraic datatypes

constr-decl::= ...  
  constr-name :  [ constr-args -> ]  typexpr  
 
type-param::= ...  
  [variance_
Refutation cases and redundancy
matching-case::= pattern  [when expr->  expr  
  pattern -> .

7.17  Syntax for Bigarray access

expr::= ...  
  expr .{  expr  { , expr } }  
  expr .{  expr  { , expr } } <-  expr

7.18  Attributes

attr-id::= lowercase-ident  
   capitalized-ident  
   attr-id .  attr-id  
 
attr-payload::=module-items ]  
   : typexpr  
   : [ specification ]  
   ? pattern  [when expr]  
 
attribute::= [@ attr-id  attr-payload ]  
 
expr::= ...  
  expr  attribute  
 
typexpr::= ...  
  typexpr  attribute  
 
pattern::= ...  
  pattern  attribute  
 
module-expr::= ...  
  module-expr  attribute  
 
module-type::= ...  
  module-type  attribute  
 
class-expr::= ...  
  class-expr  attribute  
 
class-type::= ...  
  class-type  attribute  
 
field-decl::= [mutablefield-name {attribute} :  poly-typexpr  {attribute}  
 
constr-decl::= (constr-name ∣  (){attribute} [ of constr-args ]  {attribute}  
 
item-attribute::= [@@ attr-id  attr-payload ]  
 
typedef::= ...  
  typedef  item-attribute  
 
exception-definition::= exception constr-name  { attribute }  [ of typexpr  { * typexpr } ]  
  exception constr-name =  constr  
 
module-items::= [;;] ( definition ∣  expr  { item-attribute } )  { [;;definition ∣  ;; expr  { item-attribute } }  [;;]  
 
class-binding::= ...  
  class-binding  item-attribute  
 
class-spec::= ...  
  class-spec  item-attribute  
 
classtype-def::= ...  
  classtype-def  item-attribute  
 
definition::= let [reclet-binding  { and let-binding }  
  external value-name :  typexpr =  external-declaration  { item-attribute }  
  type-definition  
  exception-definition  { item-attribute }  
  class-definition  
  classtype-definition  
  module module-name  { ( module-name :  module-type ) }  [ : module-type ]  =  module-expr  { item-attribute }  
  module type modtype-name =  module-type  { item-attribute }  
  open module-path  { item-attribute }  
  include module-expr  { item-attribute }  
  module rec module-name :  module-type =   module-expr  { item-attribute }   { and module-name :  module-type =  module-expr   { item-attribute } }  
 
specification::= val value-name :  typexpr  { item-attribute }  
  external value-name :  typexpr =  external-declaration  { item-attribute }  
  type-definition  
  exception constr-decl  { item-attribute }  
  class-specification  
  classtype-definition  
  module module-name :  module-type  { item-attribute }  
  module module-name  { ( module-name :  module-type ) } :  module-type  { item-attribute }  
  module type modtype-name  { item-attribute }  
  module type modtype-name =  module-type  { item-attribute }  
  open module-path  { item-attribute }  
  include module-type  { item-attribute }  
 
class-field-spec::= ...  
  class-field-spec  item-attribute  
 
class-field::= ...  
  class-field  item-attribute  
 
floating-attribute::= [@@@ attr-id  attr-payload ]  
 
definition::= ...  
  floating-attribute  
 
specification::= ...  
  floating-attribute  
 
class-field-spec::= ...  
  floating-attribute  
 
class-field::= ...  
  floating-attribute  
 

7.19  Extension nodes

extension::= [% attr-id  attr-payload ]  
 
expr::= ...  
  extension  
 
typexpr::= ...  
  extension  
 
pattern::= ...  
  extension  
 
module-expr::= ...  
  extension  
 
module-type::= ...  
  extension  
 
class-expr::= ...  
  extension  
 
class-type::= ...  
  extension  
 
item-extension::= [%% attr-id  attr-payload ]  
 
definition::= ...  
  item-extension  
 
specification::= ...  
  item-extension  
 
class-field-spec::= ...  
  item-extension  
 
class-field::=  ...
  item-extension  
 

7.20  Quoted strings

string-literal::= ...  
   { quoted-string-id |  ........ |  quoted-string-id }  
 
quoted-string-id::=a...z ∣  _ }  
 

7.21  Exception cases in pattern matching

pattern::= ...  
  exception pattern  
 

7.22  Extensible variant types

type-representation::= ...  
  = ..  
 
specification::= ...  
  type [type-params]  typeconstr  type-extension-spec  
 
definition::= ...  
  type [type-params]  typeconstr  type-extension-def  
 
type-extension-spec::= += [private] [|constr-decl  { | constr-decl }  
 
type-extension-def::= += [private] [|constr-def  { | constr-def }  
 
constr-def::= constr-decl  
  constr-name =  constr  
 

7.23  Generative functors

module-expr::= ...  
  functor () -> module-expr  
  module-expr ()  
 
definition::= ...  
  module module-name  { ( module-name :  module-type ) ∣  () } [ : module-type ]  =  module-expr  
 
module-type::= ...  
  functor () -> module-type  
 
specification::= ...  
  module module-name  { ( module-name :  module-type ) ∣  () } : module-type  
 

7.24  Extension-only syntax

7.24.1  Extension operators

infix-symbol::= ...  
  # {operator-chars#   {operator-char | #}  
 

7.24.2  Extension literals

float-literal::= ...  
  [-] (09) { 09∣ _ } [. { 09∣ _ }] [(e∣ E) [+∣ -] (09) { 09∣ _ }] [gz∣ GZ]  
  [-] (0x∣ 0X) (09∣ AF∣ af) { 09∣ AF∣ af∣ _ } [. { 09∣ AF∣ af∣ _ } [(p∣ P) [+∣ -] (09) { 09∣ _ }] [gz∣ GZ]  
 
integer-literal::= ...  
  [-] (09) { 09 ∣  _ }[gz∣ GZ]  
  [-] (0x∣ 0X) (09∣ AF∣ af) { 09∣ AF∣ af∣ _ } [gz∣ GZ]  
  [-] (0o∣ 0O) (07) { 07∣ _ } [gz∣ GZ]  
  [-] (0b∣ 0B) (01) { 01∣ _ } [gz∣ GZ]  
 

7.25  Inline records

constr-args::= ...  
  record-decl  
 

Chapter 19  Interfacing C with OCaml

19.1  Overview and compilation information

19.1.1  Declaring primitives

definition::= ...  
  external value-name :  typexpr =  external-declaration  
 
external-declaration::= string-literal  [ string-literal  [ string-literal ] ]

Chapter 9  The toplevel system (ocaml)

toplevel-input::=definition }+ ;;  
  expr ;;  
  # ident  [ directive-argument ] ;;  
 
directive-argument::= string-literal  
  integer-literal  
  value-path  
  true ∣  false

Chapter 16  The debugger (ocamldebug)

16.7  Examining variable values

simple-expr::= lowercase-ident  
  { capitalized-ident . }  lowercase-ident  
  *  
  $ integer  
  simple-expr .  lowercase-ident  
  simple-expr .(  integer )  
  simple-expr .[  integer ]  
  ! simple-expr  
  ( simple-expr )

Previous Up