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> SVAR AVAR STR
76 %token LB RB SL LC RC CM SC LP RP 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 PEEK PROJ PROP READ RENDER SELECT
80 %token SEQ SOURCE STAT SUB SUP SUPER THEN TRUE UNION WHERE XOR
84 %nonassoc SUP INF ELSE LOG STAT KEEP RENDER PEEK READ
92 %nonassoc SUB MEET EQ LT LE
93 %nonassoc OF PROJ COUNT ALIGN
95 %start qstr query result
97 %type <MathQL.query> query
98 %type <MathQL.result> result
102 | STR qstr { $1 ^ $2 }
111 | STR CM strs { $1 :: $3 }
115 | STR SL subpath { $1 :: $3 }
123 | path CM ppaths { $1 :: $3 }
135 | SUB { M.RefineSub }
136 | SUPER { M.RefineSuper }
140 | inv ref path { $1, $2, $3 }
143 | path IN set_exp { (false, $1, $3) }
144 | path MATCH set_exp { (true, $1, $3) }
147 | cons CM conss { $1 :: $3 }
156 | ISF conss isfalse { $2 :: $3 }
163 | path AS path { $1, Some $3 }
167 | exp CM exps { $1 :: $3 }
179 | set_exp AS path { ($3, $1) }
182 | ass CM asss { $1 :: $3 }
186 | asss SC assg { $1 :: $3 }
198 | SUP set_exp { M.GenFJoin, $2 }
199 | INF set_exp { M.GenFMeet, $2 }
202 | SOURCE { "source" }
214 { make_fun ["false"] [] [] }
216 { make_fun ["true"] [] [] }
224 { make_fun ["union"] [] $2 }
228 { make_fun ["stat"] [] [$2] }
230 { make_fun ["render"] [] [$2] }
232 { make_fun ["read"] [] [$2] }
234 { M.Ex (analyze $2) $2 }
236 { make_fun ["not"] [] [$2] }
237 | PROJ path OF set_exp
238 { make_fun ["proj"] [$2] [$4] }
240 { make_fun ["count"] [] [$2] }
241 | ALIGN set_exp IN set_exp
242 { make_fun ["align"] [] [$2; $4] }
244 { make_fun ["empty"] [] [] }
249 | LET svar BE set_exp IN set_exp
251 | FOR avar IN set_exp gen_op
252 { M.For (fst $5) $2 $4 (snd $5) }
253 | ADD distr grp_exp IN set_exp
255 | IF set_exp THEN set_exp ELSE set_exp
256 { make_fun ["if"] [] [$2; $4; $6] }
257 | PROP qualif mainc istrue isfalse attrc OF pattern set_exp
258 { M.Property (f $2) (s $2) (t $2) $3 $4 $5 $6 $8 $9 }
259 | LOG xml source set_exp
260 { make_fun ["log"; $2; $3] [] [$4] }
261 | KEEP allbut ppaths IN set_exp
262 { make_fun ["keep"; $2] $3 [$5] }
263 | KEEP allbut set_exp
264 { make_fun ["keep"; $2] [] [$3] }
265 | SELECT avar FROM set_exp WHERE set_exp
266 { M.Select $2 $4 $6 }
267 | path LC paths RC LC sets RC
268 { make_fun $1 $3 $6 }
269 | set_exp SEQ set_exp
270 { make_fun ["seq"] [] [$1; $3] }
271 | set_exp DIFF set_exp
272 { make_fun ["diff"] [] [$1; $3] }
273 | set_exp UNION set_exp
274 { make_fun ["union"] [] [$1; $3] }
275 | set_exp INTER set_exp
276 { make_fun ["intersect"] [] [$1; $3] }
277 | set_exp XOR set_exp
278 { make_fun ["xor"] [] [$1; $3] }
280 { make_fun ["or"] [] [$1; $3] }
281 | set_exp AND set_exp
282 { make_fun ["and"] [] [$1; $3] }
283 | set_exp SUB set_exp
284 { make_fun ["sub"] [] [$1; $3] }
285 | set_exp MEET set_exp
286 { make_fun ["meet"] [] [$1; $3] }
288 { make_fun ["eq"] [] [$1; $3] }
290 { make_fun ["le"] [] [$1; $3] }
292 { make_fun ["lt"] [] [$1; $3] }
294 { make_fun ["peek"] [] [$2] }
297 | set_exp CM psets { $1 :: $3 }
306 | set_exp error { $1 }
307 | EOF { raise End_of_file }
310 | path BE strs { $1, $3 }
314 | attr SC attrs { $1 :: $3 }
321 | group CM groups { $1 :: $3 }
325 | STR ATTR groups { ($1, $3) }
329 | resource SC resources { $1 :: $3 }
335 | resources error { $1 }
336 | EOF { raise End_of_file }