9e760fafe97bfcbb0a8722e660d18686b49ce43e
1 (**************************************************************************)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
8 (* Copyright 2005-2008 Institut National de Recherche en Informatique *)
9 (* et en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the Q Public License version 1.0, with the change *)
11 (* described in file LICENSE. *)
13 (**************************************************************************)
15 (* This module defines many internal naming conventions for use by the
16 two code generators, [CodeBackend] and [TableBackend]. It also offers
17 a few code generation facilities. *)
22 (* ------------------------------------------------------------------------ *)
24 (* Naming conventions. *)
26 (* The type variable associated with a nonterminal [nt]. *)
28 val ntvar
: Nonterminal.t
-> string
30 (* The variable that holds the environment. This is a parameter to all
31 functions. We do not make it a global variable because we wish to
32 preserve re-entrancy. *)
36 (* A variable used to hold a semantic value. *)
40 (* A variable used to hold a stack. *)
44 (* A variable used to hold a state. *)
48 (* A variable used to hold a token. *)
52 (* Variables used to hold start and end positions. *)
57 (* ------------------------------------------------------------------------ *)
59 (* Types for semantic values. *)
61 (* [semvtypent nt] is the type of the semantic value associated
62 with nonterminal [nt]. *)
64 val semvtypent
: Nonterminal.t
-> typ
66 (* [semvtypetok tok] is the type of the semantic value associated with
67 token [tok]. There is no such type if the token does not have a
70 val semvtypetok
: Terminal.t
-> typ list
72 (* [semvtype symbol] is the type of the semantic value associated with
75 val semvtype
: Symbol.t
-> typ list
77 (* [symvalt] returns the empty list if the symbol at hand carries no
78 semantic value and the singleton list [[f t]] if it carries a
79 semantic value of type [t]. *)
81 val symvalt
: Symbol.t
-> (typ
-> 'a
) -> 'a list
83 (* [symval symbol x] returns either the empty list or the singleton
84 list [[x]], depending on whether [symbol] carries a semantic
87 val symval
: Symbol.t
-> 'a
-> 'a list
89 (* [tokval] is a version of [symval], specialized for terminal symbols. *)
91 val tokval
: Terminal.t
-> 'a
-> 'a list
93 (* ------------------------------------------------------------------------ *)
95 (* Patterns for tokens. *)
97 (* [tokpat tok] is a pattern that matches the token [tok], without binding
98 its semantic value. *)
100 val tokpat
: Terminal.t
-> pattern
102 (* [tokpatv tok] is a pattern that matches the token [tok], and binds
103 its semantic value, if it has one, to the variable [semv]. *)
105 val tokpatv
: Terminal.t
-> pattern
107 (* [tokspat toks] is a pattern that matches any token in the set [toks],
108 without binding its semantic value. *)
110 val tokspat
: TerminalSet.t
-> pattern
112 (* [destructuretokendef name codomain bindsemv branch] generates the
113 definition of a function that destructure tokens. [name] is the
114 name of the function that is generated. [codomain] is its return
115 type. [bindsemv] tells whether the variable [semv] should be
116 bound. [branch] is applied to each (non-pseudo) terminal and must
117 produce code for each branch. *)
119 val destructuretokendef
: string -> typ
-> bool -> (Terminal.t
-> expr
) -> valdef
121 (* ------------------------------------------------------------------------ *)
123 (* Bindings for exotic keywords. *)
125 (* This provides definitions for the [$startofs], [$endofs], and
126 [$previouserror] keywords, if required by a semantic action. The
127 [ofs] keyword family is defined in terms of the [pos] family by
128 accessing the [pos_cnum] field. The [$previouserror] keyword simply
129 provides access to the current value of [env.previouserror]. *)
131 val extrabindings
: string -> Action.t
-> (pattern
* expr
) list
133 (* ------------------------------------------------------------------------ *)
135 (* A global variable holds the exception [Error]. *)
137 (* The definition of this global variable. *)
139 val excvaldef
: valdef
141 (* A reference to this global variable. *)