9e760fafe97bfcbb0a8722e660d18686b49ce43e
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / src / codePieces.mli
1 (**************************************************************************)
2 (* *)
3 (* Menhir *)
4 (* *)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
7 (* *)
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. *)
12 (* *)
13 (**************************************************************************)
14
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. *)
18
19 open IL
20 open Grammar
21
22 (* ------------------------------------------------------------------------ *)
23
24 (* Naming conventions. *)
25
26 (* The type variable associated with a nonterminal [nt]. *)
27
28 val ntvar : Nonterminal.t -> string
29
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. *)
33
34 val env : string
35
36 (* A variable used to hold a semantic value. *)
37
38 val semv : string
39
40 (* A variable used to hold a stack. *)
41
42 val stack: string
43
44 (* A variable used to hold a state. *)
45
46 val state: string
47
48 (* A variable used to hold a token. *)
49
50 val token: string
51
52 (* Variables used to hold start and end positions. *)
53
54 val startp: string
55 val endp: string
56
57 (* ------------------------------------------------------------------------ *)
58
59 (* Types for semantic values. *)
60
61 (* [semvtypent nt] is the type of the semantic value associated
62 with nonterminal [nt]. *)
63
64 val semvtypent : Nonterminal.t -> typ
65
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
68 semantic value. *)
69
70 val semvtypetok : Terminal.t -> typ list
71
72 (* [semvtype symbol] is the type of the semantic value associated with
73 [symbol]. *)
74
75 val semvtype : Symbol.t -> typ list
76
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]. *)
80
81 val symvalt : Symbol.t -> (typ -> 'a) -> 'a list
82
83 (* [symval symbol x] returns either the empty list or the singleton
84 list [[x]], depending on whether [symbol] carries a semantic
85 value. *)
86
87 val symval : Symbol.t -> 'a -> 'a list
88
89 (* [tokval] is a version of [symval], specialized for terminal symbols. *)
90
91 val tokval : Terminal.t -> 'a -> 'a list
92
93 (* ------------------------------------------------------------------------ *)
94
95 (* Patterns for tokens. *)
96
97 (* [tokpat tok] is a pattern that matches the token [tok], without binding
98 its semantic value. *)
99
100 val tokpat: Terminal.t -> pattern
101
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]. *)
104
105 val tokpatv: Terminal.t -> pattern
106
107 (* [tokspat toks] is a pattern that matches any token in the set [toks],
108 without binding its semantic value. *)
109
110 val tokspat: TerminalSet.t -> pattern
111
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. *)
118
119 val destructuretokendef: string -> typ -> bool -> (Terminal.t -> expr) -> valdef
120
121 (* ------------------------------------------------------------------------ *)
122
123 (* Bindings for exotic keywords. *)
124
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]. *)
130
131 val extrabindings: string -> Action.t -> (pattern * expr) list
132
133 (* ------------------------------------------------------------------------ *)
134
135 (* A global variable holds the exception [Error]. *)
136
137 (* The definition of this global variable. *)
138
139 val excvaldef: valdef
140
141 (* A reference to this global variable. *)
142
143 val errorval: expr
144