1 /* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 /* AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
33 let make_fun p pl xl =
34 L.check_arity p (List.length pl) (List.length xl);
38 let rec join l1 l2 = match l1, l2 with
41 | s1 :: tl1, s2 :: _ when s1 < s2 -> s1 :: join tl1 l2
42 | s1 :: _, s2 :: tl2 when s2 < s1 -> s2 :: join l1 tl2
43 | s1 :: tl1, s2 :: tl2 -> s1 :: join tl1 tl2
45 let rec iter f = function
47 | head :: tail -> join (f head) (iter f tail)
49 let rec an_set = function
57 | M.For _ _ x y -> iter an_set [x; y]
58 | M.Fun _ _ l -> iter an_set l
59 | M.Add _ g x -> join (an_grp g) (an_set x)
60 | M.Property _ _ _ _ c d _ _ x ->
61 join (an_set x) (iter an_con [c; List.concat d])
62 and fc (_, _, v) = an_set v
63 and an_con c = iter fc c
64 and fg (_, v) = an_set v
66 | M.Attr g -> iter (iter fg) g
75 %token <string> ID STR
76 %token LB RB SL IS LC RC CM SC LP RP AT DL FS DQ EOF
77 %token ADD ALIGN AND AS ATTR BE BUT COUNT DIFF DISTR ELSE EMPTY EQ EX
78 %token FALSE FOR FROM IF IN INF INTER INV ISF IST KEEP LE LET LOG LT
79 %token MAIN MATCH MEET NOT OF OR PAT PROJ PROP SELECT SEQ SOURCE STAT
80 %token SUB SUP SUPER THEN TRUE UNION WHERE XOR
83 %nonassoc SUP INF ELSE LOG STAT KEEP
91 %nonassoc SUB MEET EQ LT LE
92 %nonassoc OF PROJ COUNT ALIGN
94 %start qstr query result
96 %type <MathQL.query> query
97 %type <MathQL.result> result
101 | STR qstr { $1 ^ $2 }
110 | STR CM strs { $1 :: $3 }
114 | STR SL subpath { $1 :: $3 }
122 | path CM paths { $1 :: $3 }
129 | SUB { M.RefineSub }
130 | SUPER { M.RefineSuper }
134 | inv ref path { $1, $2, $3 }
137 | path IN set_exp { (false, $1, $3) }
138 | path MATCH set_exp { (true, $1, $3) }
141 | cons CM conss { $1 :: $3 }
150 | ISF conss isfalse { $2 :: $3 }
157 | path AS path { $1, Some $3 }
161 | exp CM exps { $1 :: $3 }
173 | set_exp AS path { ($3, $1) }
176 | ass CM asss { $1 :: $3 }
180 | asss SC assg { $1 :: $3 }
192 | SUP set_exp { M.GenFJoin, $2 }
193 | INF set_exp { M.GenFMeet, $2 }
196 | SOURCE { "source" }
208 { make_fun ["false"] [] [] }
210 { make_fun ["true"] [] [] }
218 { make_fun ["union"] [] $2 }
220 { make_fun ["union"] [] [] }
224 { make_fun ["stat"] [] [$2] }
226 { M.Ex (analyze $2) $2 }
228 { make_fun ["not"] [] [$2] }
229 | PROJ path OF set_exp
230 { make_fun ["proj"] [$2] [$4] }
232 { make_fun ["count"] [] [$2] }
233 | ALIGN set_exp IN set_exp
234 { make_fun ["align"] [] [$2; $4] }
236 { make_fun ["empty"] [] [] }
241 | LET svar BE set_exp IN set_exp
243 | FOR avar IN set_exp gen_op
244 { M.For (fst $5) $2 $4 (snd $5) }
245 | ADD distr grp_exp IN set_exp
247 | IF set_exp THEN set_exp ELSE set_exp
248 { make_fun ["diff"] [] [$2; $4; $6] }
249 | PROP qualif mainc istrue isfalse attrc OF pattern set_exp
250 { M.Property (f $2) (s $2) (t $2) $3 $4 $5 $6 $8 $9 }
251 | LOG xml source set_exp
252 { make_fun ["log"; $2; $3] [] [$4] }
253 | KEEP allbut paths IN set_exp
254 { make_fun ["keep"; $2] $3 [$5] }
255 | KEEP allbut set_exp
256 { make_fun ["keep"; $2] [] [$3] }
257 | SELECT avar FROM set_exp WHERE set_exp
258 { M.Select $2 $4 $6 }
259 | path LC paths RC LC sets RC
260 { make_fun $1 $3 $6 }
262 { make_fun $1 [] $3 }
264 { make_fun $1 [] [] }
265 | set_exp SEQ set_exp
266 { make_fun ["seq"] [] [$1; $3] }
267 | set_exp DIFF set_exp
268 { make_fun ["diff"] [] [$1; $3] }
269 | set_exp UNION set_exp
270 { make_fun ["union"] [] [$1; $3] }
271 | set_exp INTER set_exp
272 { make_fun ["intersect"] [] [$1; $3] }
273 | set_exp XOR set_exp
274 { make_fun ["xor"] [] [$1; $3] }
276 { make_fun ["or"] [] [$1; $3] }
277 | set_exp AND set_exp
278 { make_fun ["and"] [] [$1; $3] }
279 | set_exp SUB set_exp
280 { make_fun ["sub"] [] [$1; $3] }
281 | set_exp MEET set_exp
282 { make_fun ["meet"] [] [$1; $3] }
284 { make_fun ["eq"] [] [$1; $3] }
286 { make_fun ["le"] [] [$1; $3] }
288 { make_fun ["lt"] [] [$1; $3] }
291 | set_exp CM sets { $1 :: $3 }
296 | set_exp error { $1 }
297 | EOF { raise End_of_file }
300 | path IS strs { $1, $3 }
304 | attr SC attrs { $1 :: $3 }
311 | group CM groups { $1 :: $3 }
315 | STR ATTR groups { ($1, $3) }
319 | resource SC resources { $1 :: $3 }
325 | resources error { $1 }
326 | EOF { raise End_of_file }