From: Ferruccio Guidi Date: Sat, 21 Sep 2002 18:44:02 +0000 (+0000) Subject: new semantics for relation and attribute X-Git-Tag: new_mathql_before_first_merge~30 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=fb4f3bb1bafb5d5541a777758b4074ee8e2de4ae;p=helm.git new semantics for relation and attribute --- diff --git a/helm/ocaml/mathql/mQueryTLexer.mll b/helm/ocaml/mathql/mQueryTLexer.mll index 5f9b2ebac..89d62375a 100644 --- a/helm/ocaml/mathql/mQueryTLexer.mll +++ b/helm/ocaml/mathql/mQueryTLexer.mll @@ -60,6 +60,7 @@ and query_token = parse | '$' { DL } | '.' { FS } | ',' { CM } + | '/' { SL } | "and" { AND } | "attr" { ATTR } | "attribute" { ATTRIB } diff --git a/helm/ocaml/mathql/mQueryTParser.mly b/helm/ocaml/mathql/mQueryTParser.mly index a90c90e71..9af1be4f0 100644 --- a/helm/ocaml/mathql/mQueryTParser.mly +++ b/helm/ocaml/mathql/mQueryTParser.mly @@ -36,13 +36,13 @@ %{ %} %token ID STR - %token IS LC RC CM SC LP RP AT PC DL FS DQ EOF + %token SL IS LC RC CM SC LP RP AT PC DL FS DQ EOF %token AND ATTR ATTRIB BE DIFF EQ EX FALSE FUN IN INTER LET MEET NOT OR %token PAT REF REFOF REL SELECT SUB SUPER TRUE UNION WHERE %left DIFF WHERE REFOF %left OR UNION %left AND INTER - %nonassoc STR + %nonassoc REL %nonassoc NOT EX IN ATTR %start qstr query result @@ -71,20 +71,24 @@ | vvar CM vvar_list { $1 :: $3 } | vvar { [$1] } ; + qstr_path: + | STR SL qstr_path { $1 :: $3 } + | STR { [$1] } + ; ref_op: | SUB { MathQL.SubOp } | SUPER { MathQL.SuperOp } | { MathQL.ExactOp } ; val_exp: - | STR { MathQL.Const [$1] } - | FUN STR val_exp { MathQL.Fun ($2, $3) } - | ATTRIB ref_op STR val_exp { MathQL.Attribute ($2, $3, $4) } - | rvar FS vvar { MathQL.Record ($1, $3) } - | vvar { MathQL.VVar $1 } - | LC qstr_list RC { MathQL.Const $2 } - | LC RC { MathQL.Const [] } - | REFOF set_exp { MathQL.RefOf $2 } + | STR { MathQL.Const [$1] } + | FUN STR val_exp { MathQL.Fun ($2, $3) } + | ATTRIB ref_op qstr_path val_exp { MathQL.Attribute ($2, $3, $4) } + | rvar FS vvar { MathQL.Record ($1, $3) } + | vvar { MathQL.VVar $1 } + | LC qstr_list RC { MathQL.Const $2 } + | LC RC { MathQL.Const [] } + | REFOF set_exp { MathQL.RefOf $2 } ; boole_exp: | TRUE { MathQL.True } @@ -99,19 +103,19 @@ | boole_exp OR boole_exp { MathQL.Or ($1, $3) } ; set_exp: - | REF val_exp { MathQL.Ref $2 } - | PAT val_exp { MathQL.Pattern $2 } - | LP set_exp RP { $2 } - | SELECT rvar IN set_exp WHERE boole_exp { MathQL.Select ($2, $4, $6) } - | REL ref_op STR set_exp ATTR vvar_list { MathQL.Relation ($2, $3, $4, $6) } - | REL ref_op STR set_exp { MathQL.Relation ($2, $3, $4, []) } - | svar { MathQL.SVar $1 } - | rvar { MathQL.RVar $1 } - | set_exp UNION set_exp { MathQL.Union ($1, $3) } - | set_exp INTER set_exp { MathQL.Intersect ($1, $3) } - | set_exp DIFF set_exp { MathQL.Diff ($1, $3) } - | LET svar BE set_exp IN set_exp { MathQL.LetSVar ($2, $4, $6) } - | LET vvar BE val_exp IN set_exp { MathQL.LetVVar ($2, $4, $6) } + | REF val_exp { MathQL.Ref $2 } + | PAT val_exp { MathQL.Pattern $2 } + | LP set_exp RP { $2 } + | SELECT rvar IN set_exp WHERE boole_exp { MathQL.Select ($2, $4, $6) } + | REL ref_op qstr_path set_exp ATTR vvar_list { MathQL.Relation ($2, $3, $4, $6) } + | REL ref_op qstr_path set_exp { MathQL.Relation ($2, $3, $4, []) } + | svar { MathQL.SVar $1 } + | rvar { MathQL.RVar $1 } + | set_exp UNION set_exp { MathQL.Union ($1, $3) } + | set_exp INTER set_exp { MathQL.Intersect ($1, $3) } + | set_exp DIFF set_exp { MathQL.Diff ($1, $3) } + | LET svar BE set_exp IN set_exp { MathQL.LetSVar ($2, $4, $6) } + | LET vvar BE val_exp IN set_exp { MathQL.LetVVar ($2, $4, $6) } ; query: | set_exp EOF { $1 } diff --git a/helm/ocaml/mathql/mQueryUtil.ml b/helm/ocaml/mathql/mQueryUtil.ml index 73006b606..450e40210 100644 --- a/helm/ocaml/mathql/mQueryUtil.ml +++ b/helm/ocaml/mathql/mQueryUtil.ml @@ -54,7 +54,7 @@ let text_of_query x = | M.SuperOp -> "super " in let txt_vvar_list l = - txt_list txt_vvar ", " l + l in let rec txt_val = function | M.Const [s] -> txt_qstr s @@ -62,7 +62,7 @@ let text_of_query x = | M.VVar vv -> txt_vvar vv | M.Record (rv, vv) -> txt_rvar rv ^ "." ^ txt_vvar vv | M.Fun (s, x) -> "fun " ^ txt_qstr s ^ " " ^ txt_val x - | M.Attribute (r, s, x) -> "attribute " ^ txt_ref r ^ txt_qstr s ^ " " ^ txt_val x + | M.Attribute (r, p, x) -> "attribute " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_val x | M.RefOf x -> "refof " ^ txt_set x and txt_boole = function | M.False -> "false" @@ -77,8 +77,8 @@ let text_of_query x = and txt_set = function | M.SVar sv -> txt_svar sv | M.RVar rv -> txt_rvar rv - | M.Relation (r, s, x, []) -> "relation " ^ txt_ref r ^ txt_qstr s ^ " " ^ txt_set x - | M.Relation (r, s, x, l) -> "relation " ^ txt_ref r ^ txt_qstr s ^ " " ^ txt_set x ^ " attr " ^ txt_vvar_list l + | M.Relation (r, p, x, []) -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x + | M.Relation (r, p, x, l) -> "relation " ^ txt_ref r ^ txt_list txt_qstr "/" p ^ " " ^ txt_set x ^ " attr " ^ txt_list txt_vvar ", " l | M.Union (x, y) -> "(" ^ txt_set x ^ " union " ^ txt_set y ^ ")" | M.Intersect (x, y) -> "(" ^ txt_set x ^ " intersect " ^ txt_set y ^ ")" | M.Diff (x, y) -> "(" ^ txt_set x ^ " diff " ^ txt_set y ^ ")" @@ -87,7 +87,7 @@ let text_of_query x = | M.Select (rv, x, y) -> "select " ^ txt_rvar rv ^ " in " ^ txt_set x ^ " where " ^ txt_boole y | M.Pattern x -> "pattern " ^ txt_val x | M.Ref x -> "ref " ^ txt_val x - in + in txt_set x let text_of_result x sep = @@ -100,7 +100,7 @@ let text_of_result x sep = | (s, []) -> txt_qstr s | (s, l) -> txt_qstr s ^ " attr " ^ txt_list txt_group ", " l in - let txt_set l = txt_list txt_res ("; " ^ sep) l in + let txt_set l = txt_list txt_res ("; " ^ sep) l ^ sep in txt_set x let query_of_text lexbuf = diff --git a/helm/ocaml/mathql/mathQL.ml b/helm/ocaml/mathql/mathQL.ml index b424d110b..60b19297a 100644 --- a/helm/ocaml/mathql/mathQL.ml +++ b/helm/ocaml/mathql/mathQL.ml @@ -47,13 +47,15 @@ type refine_op = ExactOp | SubOp | SuperOp +type path = string list + type vvar_list = vvar list type set_exp = SVar of svar | RVar of rvar | Ref of val_exp | Pattern of val_exp - | Relation of refine_op * string * set_exp * vvar_list + | Relation of refine_op * path * set_exp * vvar_list | Select of rvar * set_exp * boole_exp | Union of set_exp * set_exp | Intersect of set_exp * set_exp @@ -76,7 +78,7 @@ and val_exp = Const of string list | Record of rvar * vvar | VVar of vvar | Fun of string * val_exp - | Attribute of refine_op * string * val_exp + | Attribute of refine_op * path * val_exp type query = set_exp