X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2FmQueryTParser.mly;h=54f8f837ccd0af63ff950cfdd7babb02d7ffbbea;hb=381006cf8b418cfdeaf145ab7df9e8f2b19ae2e6;hp=4945edfc0531bcf3ee16acaea184579688a0f0bb;hpb=efdc3184ccd0738fe48aa0056fc444fba23329e8;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/mQueryTParser.mly b/helm/ocaml/mathql_interpreter/mQueryTParser.mly index 4945edfc0..54f8f837c 100644 --- a/helm/ocaml/mathql_interpreter/mQueryTParser.mly +++ b/helm/ocaml/mathql_interpreter/mQueryTParser.mly @@ -28,15 +28,17 @@ %{ module M = MathQL + module I = M.I + module U = AvsUtil module L = MQILib let make_fun p pl xl = L.fun_arity p (List.length pl) (List.length xl); - M.Fun p pl xl + M.Fun (p, pl, xl) let make_gen p xl = L.gen_arity p (List.length xl); - M.Gen p xl + M.Gen (p, xl) let analyze x = let rec join l1 l2 = match l1, l2 with @@ -51,26 +53,27 @@ | head :: tail -> join (f head) (iter f tail) in let rec an_set = function - | M.Const _ + | M.Const x -> iter fv x | M.SVar _ | M.AVar _ - | M.Ex _ -> [] - | M.Dot rv _ -> [rv] - | M.Let _ x y - | M.Select _ x y - | M.For _ _ x y -> iter an_set [x; y] - | M.While _ x y -> iter an_set [x; y] - | M.Fun _ _ l -> iter an_set l - | M.Gen _ l -> iter an_set l - | M.Add _ g x -> join (an_grp g) (an_set x) - | M.Property _ _ _ _ c d _ _ x -> + | M.Ex _ -> [] + | M.Dot (rv, _) -> [rv] + | M.Let (_, x, y) + | M.Select (_, x, y) + | M.For (_, _, x, y) -> iter an_set [x; y] + | M.While (_, x, y) -> iter an_set [x; y] + | M.Fun (_, _, l) -> iter an_set l + | M.Gen (_, l) -> iter an_set l + | M.Add (_, g, x) -> join (an_grp g) (an_set x) + | M.Property (_, _, _, _, c, d, _, _, x) -> join (an_set x) (iter an_con [c; List.concat d]) and fc (_, _, v) = an_set v and an_con c = iter fc c and fg (_, v) = an_set v and an_grp = function | M.Attr g -> iter (iter fg) g - | M.From _ -> [] + | M.From _ -> [] + and fv (_, g) = iter (iter fg) g in an_set x @@ -182,17 +185,6 @@ | PAT { true } | { false } ; - ass: - | set_exp AS path { ($3, $1) } - ; - asss: - | ass CM asss { $1 :: $3 } - | ass { [$1] } - ; - assg: - | asss SC assg { $1 :: $3 } - | asss { [$1] } - ; distr: | DISTR { true } | { false } @@ -213,8 +205,8 @@ | { "text" } ; grp_exp: - | assg { M.Attr $1 } - | avar { M.From $1 } + | x_groups { M.Attr $1 } + | avar { M.From $1 } ; set_exp: | STAT set_exp { make_fun ["stat"] [] [$2] } @@ -247,20 +239,20 @@ | IF set_exp THEN set_exp ELSE set_exp { make_fun ["if"] [] [$2; $4; $6] } | STR { M.Const [$1, []] } - | LB resources RB { M.Const $2 } - | avar FS path { M.Dot $1 $3 } + | LB x_resources RB { M.Const $2 } + | avar FS path { M.Dot ($1, $3) } | LP set_exp RP { $2 } - | EX set_exp { M.Ex (analyze $2) $2 } + | EX set_exp { M.Ex (analyze $2, $2) } | svar { M.SVar $1 } | avar { M.AVar $1 } - | LET svar BE set_exp IN set_exp { M.Let (Some $2) $4 $6 } - | set_exp SEQ set_exp { M.Let None $1 $3 } - | FOR avar IN set_exp gen_op { M.For (fst $5) $2 $4 (snd $5) } - | WHILE set_exp gen_op { M.While (fst $3) $2 (snd $3) } - | ADD distr grp_exp IN set_exp { M.Add $2 $3 $5 } + | LET svar BE set_exp IN set_exp { M.Let (Some $2, $4, $6) } + | set_exp SEQ set_exp { M.Let (None, $1, $3) } + | FOR avar IN set_exp gen_op { M.For (fst $5, $2, $4, snd $5) } + | WHILE set_exp gen_op { M.While (fst $3, $2, snd $3) } + | ADD distr grp_exp IN set_exp { M.Add ($2, $3, $5) } | PROP qualif mainc istrue isfalse attrc OF pattern set_exp - { M.Property (f $2) (s $2) (t $2) $3 $4 $5 $6 $8 $9 } - | SELECT avar FROM set_exp WHERE set_exp { M.Select $2 $4 $6 } + { M.Property (f $2, s $2, t $2, $3, $4, $5, $6, $8, $9) } + | SELECT avar FROM set_exp WHERE set_exp { M.Select ($2, $4, $6) } | GEN path LC sets RC { make_gen $2 $4 } | GEN path IN set_exp { make_gen $2 [$4] } ; @@ -277,13 +269,39 @@ | set_exp error { $1 } | EOF { raise End_of_file } ; + + x_attr: + | path BE set_exp { ($1, $3) } + | path { ($1, make_fun ["empty"] [] []) } + ; + x_attrs: + | x_attr SC x_attrs { $1 :: $3 } + | x_attr { [$1] } + ; + x_group: + LC x_attrs RC { $2 } + ; + x_groups: + | x_group CM x_groups { $1 :: $3 } + | x_group { [$1] } + ; + x_resource: + | STR ATTR x_groups { ($1, $3) } + | STR { ($1, []) } + ; + x_resources: + | x_resource SC x_resources { $1 :: $3 } + | x_resource { [$1] } + | { [] } + ; + attr: - | path BE strs { $1, $3 } - | path { $1, [] } + | path BE strs { U.grp_make_x $1 $3 } + | path { U.grp_make_x $1 [] } ; attrs: - | attr SC attrs { $1 :: $3 } - | attr { [$1] } + | attr SC attrs { I.grp_union $1 $3 } + | attr { $1 } ; group: LC attrs RC { $2 } @@ -293,13 +311,13 @@ | group { [$1] } ; resource: - | STR ATTR groups { ($1, $3) } - | STR { ($1, []) } + | STR ATTR groups { U.make_x $1 $3 } + | STR { U.make_x $1 [] } ; resources: - | resource SC resources { $1 :: $3 } - | resource { [$1] } - | { [] } + | resource SC resources { I.union $1 $3 } + | resource { $1 } + | { U.val_false } ; result: | resources { $1 }