]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql/mQueryTParser.mly
new semantics for relation and attribute
[helm.git] / helm / ocaml / mathql / mQueryTParser.mly
1 /* Copyright (C) 2000, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  */
25
26 /******************************************************************************/
27 /*                                                                            */
28 /*                               PROJECT HELM                                 */
29 /*                                                                            */
30 /*                     Ferruccio Guidi <fguidi@cs.unibo.it>                   */
31 /*                                 23/05/2002                                 */
32 /*                                                                            */
33 /*                                                                            */
34 /******************************************************************************/
35
36 %{
37 %}
38    %token    <string> ID STR
39    %token    SL IS LC RC CM SC LP RP AT PC DL FS DQ EOF 
40    %token    AND ATTR ATTRIB BE DIFF EQ EX FALSE FUN IN INTER LET MEET NOT OR
41    %token    PAT REF REFOF REL SELECT SUB SUPER TRUE UNION WHERE
42    %left     DIFF WHERE REFOF  
43    %left     OR UNION
44    %left     AND INTER
45    %nonassoc REL
46    %nonassoc NOT EX IN ATTR
47
48    %start    qstr query result
49    %type     <string>        qstr      
50    %type     <MathQL.query>  query
51    %type     <MathQL.result> result 
52 %%
53    qstr:
54       | DQ       { ""      }
55       | STR qstr { $1 ^ $2 }
56    ;
57    svar:
58       | PC ID { $2 }
59    ;
60    rvar:
61       | AT ID { $2 }
62    ;
63    vvar:
64       | DL ID { $2 }
65    ;
66    qstr_list:
67       | STR CM qstr_list { $1 :: $3 }
68       | STR              { [$1]     } 
69    ;
70    vvar_list:
71       | vvar CM vvar_list { $1 :: $3 }
72       | vvar              { [$1]     }
73    ;
74    qstr_path:
75       | STR SL qstr_path { $1 :: $3 }
76       | STR              { [$1]     } 
77    ;
78    ref_op:
79       | SUB   { MathQL.SubOp   }
80       | SUPER { MathQL.SuperOp }
81       |       { MathQL.ExactOp }
82    ;
83    val_exp:
84       | STR                             { MathQL.Const [$1]             } 
85       | FUN STR val_exp                 { MathQL.Fun ($2, $3)           }
86       | ATTRIB ref_op qstr_path val_exp { MathQL.Attribute ($2, $3, $4) }
87       | rvar FS vvar                    { MathQL.Record ($1, $3)        }
88       | vvar                            { MathQL.VVar $1                }
89       | LC qstr_list RC                 { MathQL.Const $2               }
90       | LC RC                           { MathQL.Const []               }
91       | REFOF set_exp                   { MathQL.RefOf $2               }
92    ;
93    boole_exp:
94       | TRUE                    { MathQL.True          }
95       | FALSE                   { MathQL.False         }
96       | LP boole_exp RP         { $2                   }
97       | NOT boole_exp           { MathQL.Not $2        }
98       | EX boole_exp            { MathQL.Ex $2         }
99       | val_exp SUB val_exp     { MathQL.Sub ($1, $3)  }
100       | val_exp MEET val_exp    { MathQL.Meet ($1, $3) }
101       | val_exp EQ val_exp      { MathQL.Eq ($1, $3)   }
102       | boole_exp AND boole_exp { MathQL.And ($1, $3)  }
103       | boole_exp OR boole_exp  { MathQL.Or ($1, $3)   }
104    ;   
105    set_exp:
106       | REF val_exp                                 { MathQL.Ref $2                    }
107       | PAT val_exp                                 { MathQL.Pattern $2                } 
108       | LP set_exp RP                               { $2                               }
109       | SELECT rvar IN set_exp WHERE boole_exp      { MathQL.Select ($2, $4, $6)       }
110       | REL ref_op qstr_path set_exp ATTR vvar_list { MathQL.Relation ($2, $3, $4, $6) }
111       | REL ref_op qstr_path set_exp                { MathQL.Relation ($2, $3, $4, []) }
112       | svar                                        { MathQL.SVar $1                   }
113       | rvar                                        { MathQL.RVar $1                   }
114       | set_exp UNION set_exp                       { MathQL.Union ($1, $3)            }
115       | set_exp INTER set_exp                       { MathQL.Intersect ($1, $3)        }
116       | set_exp DIFF set_exp                        { MathQL.Diff ($1, $3)             }
117       | LET svar BE set_exp IN set_exp              { MathQL.LetSVar ($2, $4, $6)      }      
118       | LET vvar BE val_exp IN set_exp              { MathQL.LetVVar ($2, $4, $6)      }      
119    ;
120    query:
121       | set_exp EOF { $1 }
122    ;
123    attribute:
124       | STR IS qstr_list { ($1, $3) }
125       | STR              { ($1, []) }
126    ;
127    attr_list:
128       | attribute SC attr_list { $1 :: $3 }
129       | attribute              { [$1]     }
130    ;
131    group:
132       LC attr_list RC { $2 }
133    ;
134    group_list:
135       | group CM group_list { $1 :: $3 }
136       | group               { [$1]     }
137    ;
138    resource:
139       | STR ATTR group_list { ($1, $3) }
140       | STR                 { ($1, []) }
141    ;
142    resource_list:
143       | resource SC resource_list { $1 :: $3 }
144       | resource                  { [$1]     }
145       |                           { []       }
146    ;   
147    result:
148       | resource_list EOF         { $1 }