1 /**************************************************************************/
2 /* */
3 /* OCaml */
4 /* */
5 /* Jerome Vouillon, projet Cristal, INRIA Rocquencourt */
6 /* OCaml port by John Malecki and Xavier Leroy */
7 /* */
8 /* Copyright 1996 Institut National de Recherche en Informatique et */
9 /* en Automatique. */
10 /* */
11 /* All rights reserved. This file is distributed under the terms of */
12 /* the GNU Lesser General Public License version 2.1, with the */
13 /* special exception on linking described in the file LICENSE. */
14 /* */
15 /**************************************************************************/
16
17 %{
18
19 open Int64ops
20 open Input_handling
21 open Longident
22 open Parser_aux
23 open Debugcom
24
25 %}
26
27 %token <string> ARGUMENT
28 %token <string> LIDENT
29 %token <string> UIDENT
30 %token <string> OPERATOR
31 %token <int64> INTEGER
32 %token STAR /* * */
33 %token MINUS /* - */
34 %token DOT /* . */
35 %token COLON /* : */
36 %token HASH /* # */
37 %token AT /* @ */
38 %token DOLLAR /* $ */
39 %token BANG /* ! */
40 %token LPAREN /* ( */
41 %token RPAREN /* ) */
42 %token LBRACKET /* [ */
43 %token RBRACKET /* ] */
44 %token EOL
45
46 %right DOT
47 %right BANG
48
49 %start argument_list_eol
50 %type <string list> argument_list_eol
51
52 %start argument_eol
53 %type <string> argument_eol
54
55 %start integer_list_eol
56 %type <int list> integer_list_eol
57
58 %start integer_eol
59 %type <int> integer_eol
60
61 %start int64_eol
62 %type <int64> int64_eol
63
64 %start integer
65 %type <int> integer
66
67 %start opt_integer_eol
68 %type <int option> opt_integer_eol
69
70 %start opt_signed_integer_eol
71 %type <int option> opt_signed_integer_eol
72
73 %start opt_signed_int64_eol
74 %type <int64 option> opt_signed_int64_eol
75
76 %start identifier
77 %type <string> identifier
78
79 %start identifier_eol
80 %type <string> identifier_eol
81
82 %start identifier_or_eol
83 %type <string option> identifier_or_eol
84
85 %start opt_identifier
86 %type <string option> opt_identifier
87
88 %start opt_identifier_eol
89 %type <string option> opt_identifier_eol
90
91 %start expression_list_eol
92 %type <Parser_aux.expression list> expression_list_eol
93
94 %start break_argument_eol
95 %type <Parser_aux.break_arg> break_argument_eol
96
97 %start list_arguments_eol
98 %type <Longident.t option * int option * int option> list_arguments_eol
99
100 %start end_of_line
101 %type <unit> end_of_line
102
103 %start longident_eol
104 %type <Longident.t> longident_eol
105
106 %start opt_longident
107 %type <Longident.t option> opt_longident
108
109 %start opt_longident_eol
110 %type <Longident.t option> opt_longident_eol
111
112 %%
113
114 /* Raw arguments */
115
116 argument_list_eol :
117 ARGUMENT argument_list_eol
118 { $1::$2 }
119 | end_of_line
120 { [] };
121
122 argument_eol :
123 ARGUMENT end_of_line
124 { $1 };
125
126 /* Integer */
127
128 integer_list_eol :
129 INTEGER integer_list_eol
130 { (to_int $1) :: $2 }
131 | end_of_line
132 { [] };
133
134 integer_eol :
135 INTEGER end_of_line
136 { to_int $1 };
137
138 int64_eol :
139 INTEGER end_of_line
140 { $1 };
141
142 integer :
143 INTEGER
144 { to_int $1 };
145
146 opt_integer_eol :
147 INTEGER end_of_line
148 { Some (to_int $1) }
149 | end_of_line
150 { None };
151
152 opt_int64_eol :
153 INTEGER end_of_line
154 { Some $1 }
155 | end_of_line
156 { None };
157
158 opt_signed_integer_eol :
159 MINUS integer_eol
160 { Some (- $2) }
161 | opt_integer_eol
162 { $1 };
163
164 opt_signed_int64_eol :
165 MINUS int64_eol
166 { Some (Int64.neg $2) }
167 | opt_int64_eol
168 { $1 };
169
170 /* Identifiers and long identifiers */
171
172 longident :
173 LIDENT { Lident $1 }
174 | module_path DOT LIDENT { Ldot($1, $3) }
175 | OPERATOR { Lident $1 }
176 | module_path DOT OPERATOR { Ldot($1, $3) }
177 | module_path DOT LPAREN OPERATOR RPAREN { Ldot($1, $4) }
178 ;
179
180 module_path :
181 UIDENT { Lident $1 }
182 | module_path DOT UIDENT { Ldot($1, $3) }
183 ;
184
185 longident_eol :
186 longident end_of_line { $1 };
187
188 opt_longident :
189 UIDENT { Some (Lident $1) }
190 | LIDENT { Some (Lident $1) }
191 | module_path DOT UIDENT { Some (Ldot($1, $3)) }
192 | { None };
193
194 opt_longident_eol :
195 opt_longident end_of_line { $1 };
196
197 identifier :
198 LIDENT { $1 }
199 | UIDENT { $1 };
200
201 identifier_eol :
202 identifier end_of_line { $1 };
203
204 identifier_or_eol :
205 identifier { Some $1 }
206 | end_of_line { None };
207
208 opt_identifier :
209 identifier { Some $1 }
210 | { None };
211
212 opt_identifier_eol :
213 opt_identifier end_of_line { $1 };
214
215 /* Expressions */
216
217 expression:
218 longident { E_ident $1 }
219 | STAR { E_result }
220 | DOLLAR INTEGER { E_name (to_int $2) }
221 | expression DOT INTEGER { E_item($1, (to_int $3)) }
222 | expression DOT LBRACKET INTEGER RBRACKET { E_item($1, (to_int $4)) }
223 | expression DOT LPAREN INTEGER RPAREN { E_item($1, (to_int $4)) }
224 | expression DOT LIDENT { E_field($1, $3) }
225 | BANG expression { E_field($2, "contents") }
226 | LPAREN expression RPAREN { $2 }
227 ;
228
229 /* Lists of expressions */
230
231 expression_list_eol :
232 expression expression_list_eol { $1::$2 }
233 | end_of_line { [] }
234 ;
235
236 /* Arguments for breakpoint */
237
238 break_argument_eol :
239 end_of_line { BA_none }
240 | integer_eol { BA_pc {frag = 0; pos = $1} }
241 | INTEGER COLON integer_eol { BA_pc {frag = to_int $1;
242 pos = $3} }
243 | expression end_of_line { BA_function $1 }
244 | AT opt_longident INTEGER opt_integer_eol { BA_pos1 ($2, (to_int $3), $4)}
245 | AT opt_longident HASH integer_eol { BA_pos2 ($2, $4) }
246 ;
247
248 /* Arguments for list */
249
250 list_arguments_eol :
251 opt_longident integer opt_integer_eol
252 { ($1, Some $2, $3) }
253 | opt_longident_eol
254 { ($1, None, None) };
255
256 /* End of line */
257
258 end_of_line :
259 EOL { stop_user_input () }
260 ;
261