Abstract Syntax Tree
From Gallium
Here is the Camlp4 syntactic and abstract representation of OCaml programs:
Contents |
[edit]
Identifiers
Quotation | Signification | AST |
---|---|---|
<:ident< a . b >> | Access in module | IdAcc of Loc.t and ident and ident |
<:ident< a b >> | Application | IdApp of Loc.t and ident and ident |
<:ident< $lid:i$ >> | Lowercase identifier | IdLid of Loc.t and string |
<:ident< $uid:i$ >> | Uppercase identifier | IdUid of Loc.t and string |
<:ident< $anti:s$ >> | Antiquotation | IdAnt of Loc.t and string |
[edit]
Types
Quotation | Signification | AST |
---|---|---|
<:ctyp< >> | Empty type | TyNil of Loc.t |
<:ctyp< t as t >> | Type aliasing | TyAli of Loc.t and ctyp and ctyp |
<:ctyp< _ >> | Wildcard | TyAny of Loc.t |
<:ctyp< t t >> | Application | TyApp of Loc.t and ctyp and ctyp |
<:ctyp< t -> t >> | Arrow | TyArr of Loc.t and ctyp and ctyp |
<:ctyp< #i >> | Class type | TyCls of Loc.t and ident |
<:ctyp< ~s >> | Label type | TyLab of Loc.t and string and ctyp |
<:ctyp< $id:i$ >> | Type identifier | TyId of Loc.t and ident |
<:ctyp< t == t >> | Type manifest | TyMan of Loc.t and ctyp and ctyp |
<:ctyp< type t 'a 'b 'c = t constraint t = t constraint t = t >> | Type declaration | TyDcl of Loc.t and string and list ctyp and ctyp and list (ctyp * ctyp) |
<:ctyp< < (t)? (..)? > >> | Object type | TyObj of Loc.t and ctyp and meta_bool |
<:ctyp< ?s >> | Optional label type | TyOlb of Loc.t and string and ctyp |
<:ctyp< ! t . t >> | Polymorphic type | TyPol of Loc.t and ctyp and ctyp |
<:ctyp< 's >> | TyQuo of Loc.t and string | |
<:ctyp< +'s >> | TyQuP of Loc.t and string | |
<:ctyp< -'s >> | TyQuM of Loc.t and string | |
<:ctyp< `s >> | Polymorphic variant | TyVrn of Loc.t and string |
<:ctyp< { t } >> | Record | TyRec of Loc.t and ctyp |
<:ctyp< t : t >> | Field declaration | TyCol of Loc.t and ctyp and ctyp |
<:ctyp< t; t >> | Semicolon-separated type list | TySem of Loc.t and ctyp and ctyp |
<:ctyp< t, t >> | Comma-separated type list | TyCom of Loc.t and ctyp and ctyp |
<:ctyp< [ t ] >> | Sum type | TySum of Loc.t and ctyp |
<:ctyp< t of t >> | TyOf of Loc.t and ctyp and ctyp | |
<:ctyp< t and t >> | TyAnd of Loc.t and ctyp and ctyp | |
<:ctyp< t | t >> | "Or" pattern between types | TyOr of Loc.t and ctyp and ctyp |
<:ctyp< private t >> | Private type | TyPrv of Loc.t and ctyp |
<:ctyp< mutable t >> | Mutable type | TyMut of Loc.t and ctyp |
<:ctyp< ( t ) >> | Tuple | TyTup of Loc.t and ctyp |
<:ctyp< t * t >> | TySta of Loc.t and ctyp and ctyp | |
<:ctyp< [ = t ] >> | TyVrnEq of Loc.t and ctyp | |
<:ctyp< [ > t ] >> | TyVrnSup of Loc.t and ctyp | |
<:ctyp< [ < t ] >> | TyVrnInf of Loc.t and ctyp | |
<:ctyp< [ < t > t ] >> | TyVrnInfSup of Loc.t and ctyp and ctyp | |
<:ctyp< t & t >> | TyAmp of Loc.t and ctyp and ctyp | |
<:ctyp< t of & t >> | TyOfAmp of Loc.t and ctyp and ctyp | |
<:ctyp< $anti:s$ >> | Antiquotation | TyAnt of Loc.t and string |
[edit]
Patterns
Quotation | Signification | AST |
---|---|---|
<:patt< >> | Empty pattern | PaNil of Loc.t |
<:patt< $id:i$ >> | Identifier | PaId of Loc.t and ident |
<:patt< p as p >> | Alias | PaAli of Loc.t and patt and patt |
<:patt< $anti:s$ >> | Antiquotation | PaAnt of Loc.t and string |
<:patt< _ >> | Wildcard | PaAny of Loc.t |
<:patt< p p >> | Application | PaApp of Loc.t and patt and patt |
<:patt< [| p |] >> | Array | PaArr of Loc.t and patt |
<:patt< p, p >> | Comma-separated pattern list | PaCom of Loc.t and patt and patt |
<:patt< p; p >> | Semicolon-separated pattern list | PaSem of Loc.t and patt and patt |
<:patt< $chr:c$ >> | Character | PaChr of Loc.t and string |
<:patt< $int:i$ >> | Integer | PaInt of Loc.t and string |
<:patt< $int32:i$ >> | Int32 | PaInt32 of Loc.t and string |
<:patt< $int64:i$ >> | Int64 | PaInt64 of Loc.t and string |
<:patt< $nativeint:i$ >> | NativeInt | PaNativeInt of Loc.t and string |
<:patt< $flo:f$ >> | Float | PaFlo of Loc.t and string |
<:patt< ~s >> <:patt< s:(p) >> | Label | PaLab of Loc.t and string and patt |
<:patt< ?s >> <:patt< ?s:(p) >> | Optional label | PaOlb of Loc.t and string and patt |
<:patt< ?s:(p = e) >> <:patt< ?(p = e) >> | Optional label with default value | PaOlbi of Loc.t and string and patt and expr |
<:patt< p | p >> | Or | PaOrp of Loc.t and patt and patt |
<:patt< p .. p >> | Pattern range | PaRng of Loc.t and patt and patt |
<:patt< { p } >> | Record | PaRec of Loc.t and patt |
<:patt< i = p >> | Equality | PaEq of Loc.t and ident and patt |
<:patt< $str:s$ >> | String | PaStr of Loc.t and string |
<:patt< ( p ) >> | Tuple | PaTup of Loc.t and patt |
<:patt< (p : t) >> | Type constraint | PaTyc of Loc.t and patt and ctyp |
<:patt< #i >> | PaTyp of Loc.t and ident | |
<:patt< `s >> | Polymorphic variant | PaVrn of Loc.t and string |
[edit]
Expressions
Quotation | Signification | AST |
---|---|---|
<:expr< >> | Empty expression | ExNil of Loc.t |
<:expr< $id:i$ >> | Identifier | ExId of Loc.t and ident |
<:expr< e.e >> | Access in module | ExAcc of Loc.t and expr and expr |
<:expr< $anti:s$ >> | Antiquotation | ExAnt of Loc.t and string |
<:expr< e e >> | Application | ExApp of Loc.t and expr and expr |
<:expr< e.(e) >> | Array access | ExAre of Loc.t and expr and expr |
<:expr< [| e |] >> | Array declaration | ExArr of Loc.t and expr |
<:expr< e; e >> | Semicolon-separated expression list | ExSem of Loc.t and expr and expr |
<:expr< assert False >> | assert False | ExAsf of Loc.t |
<:expr< assert e >> | assert e | ExAsr of Loc.t and expr |
<:expr< e := e >> | Assignment | ExAss of Loc.t and expr and expr |
<:expr< $chr:c$ >> | Character | ExChr of Loc.t and string |
<:expr< (e : t) >> <:expr< (e : t :> t) >> | Coercion | ExCoe of Loc.t and expr and ctyp and ctyp |
<:expr< $flo:f$ >> | Float | ExFlo of Loc.t and string |
<:expr< for s = e to/downto e do { e } >> | For loop | ExFor of Loc.t and string and expr and expr and meta_bool and expr |
<:expr< fun [ a ] >> | Function with match case | ExFun of Loc.t and match_case |
<:expr< if e then e else e >> | if/then/else | ExIfe of Loc.t and expr and expr and expr |
<:expr< $int:i$ >> | Int | ExInt of Loc.t and string |
<:expr< $int32:i$ >> | Int32 | ExInt32 of Loc.t and string |
<:expr< $int64:i$ >> | Int64 | ExInt64 of Loc.t and string |
<:expr< $nativeint:i$ >> | NativeInt | ExNativeInt of Loc.t and string |
<:expr< ~s >> <:expr< ~s:e >> | Label argument with/without expression | ExLab of Loc.t and string and expr |
<:expr< lazy e >> | Lazy evaluation | ExLaz of Loc.t and expr |
<:expr< let b in e >> <:expr< let rec b in e >> | Let statement with/without recursion | ExLet of Loc.t and meta_bool and binding and expr |
<:expr< let module s = me in e >> | "Let module in" construct | ExLmd of Loc.t and string and module_expr and expr |
<:expr< match e with [ a ] >> | Match case | ExMat of Loc.t and expr and match_case |
<:expr< new $id:i$ >> | New object | ExNew of Loc.t and ident |
<:expr< object ((p))? (cst)? end >> | Object declaration | ExObj of Loc.t and patt and class_str_item |
<:expr< ?s >> <:expr< ?s:e >> | Optional label | ExOlb of Loc.t and string and expr |
<:expr< {< b >} >> | Overloading | ExOvr of Loc.t and rec_binding |
<:expr< { b } >> <:expr< { (e) with b } >> | Record | ExRec of Loc.t and rec_binding and expr |
<:expr< do { e } >> | Sequence with "do" statement | ExSeq of Loc.t and expr |
<:expr< e#s >> | Method call | ExSnd of Loc.t and expr and string |
<:expr< e.[e] >> | String access | ExSte of Loc.t and expr and expr |
<:expr< $str:s$ >> | String | ExStr of Loc.t and string |
<:expr< try e with [ a ] >> | "Try .. with" construct | ExTry of Loc.t and expr and match_case |
<:expr< (e) >> | Tuple | ExTup of Loc.t and expr |
<:expr< e, e >> | Comma-separated expression list | ExCom of Loc.t and expr and expr |
<:expr< (e : t) >> | Type constraint | ExTyc of Loc.t and expr and ctyp |
<:expr< `s >> | Polymorphic variant | ExVrn of Loc.t and string |
<:expr< while e do { e } >> | "While .. do" constraint | ExWhi of Loc.t and expr and expr |
[edit]
Module types
module_type, mt ::= | (* empty *) | ident | functor (s : mt) -> mt | 's | sig sg end | mt with wc | $s$
[edit]
Signature items
sig_item, sg ::= | (* empty *) | class cict | class type cict | sg ; sg | #s | #s e | exception t | external s : t = s ... s | include mt | module s : mt | module rec mb | module type s = mt | open i | type t | value s : t | $s$
[edit]
With constraints
with_constraint, with_constr, wc ::= | wc and wc | type t = t | module i = i
[edit]
Bindings
binding, bi ::= | bi and bi | p = e
[edit]
Record bindings
record_binding, rec_binding, rb ::= | rb ; rb | x = e
[edit]
Recursive module bindings
module_binding, mb ::= | (* empty *) | mb and mb | s : mt = me | s : mt | $s$
[edit]
Match cases
match_case, mc ::= | (* empty *) | mc | mc | p when e -> e | p -> e (* a sugar for << p when e1 -> e2 >> where e1 is the empty expression *)
[edit]
Module expressions
module_expression, module_expr, me ::= | (* empty *) | ident | me me | functor (s : mt) -> me | struct st end | (me : mt) | $s$
[edit]
Structure items
structure_item, str_item, st ::= | (* empty *) | class cice | class type cict | st ; st | #s | #s e | exception t or exception t = i | e | external s : t = s ... s | include me | module s = me | module rec mb | module type s = mt | open i | type t | value b or value rec bi | $s$
[edit]
Class types
class_type, ct ::= | (* empty *) | (virtual)? i ([ t ])? | [t] -> ct | object (t) csg end | ct and ct | ct : ct | ct = ct | $s$
[edit]
Class signature items
class_signature_item, class_sig_item, csg ::= | (* empty *) | type t = t | csg ; csg | inherit ct | method s : t or method private s : t | value (virtual)? (mutable)? s : t | method virtual (mutable)? s : t | $s$
[edit]
Class expressions
class_expression, class_expr, ce ::= | (* empty *) | ce e | (virtual)? i ([ t ])? | fun p -> ce | let (rec)? bi in ce | object (p) (cst) end | ce : ct | ce and ce | ce = ce | $s$
[edit]
Class structure items
class_structure_item, class_str_item, cst ::= | (* empty *) | cst ; cst | type t = t | inherit ce or inherit ce as s | initializer e | method (private)? s : t = e or method (private)? s = e | value (mutable)? s = e | method virtual (private)? s : t | value virtual (private)? s : t | $s$