]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql/mQueryTParser.mly
...
[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    open MathQL
38 %}
39    %token    <string> ID STR
40    %token    <MathQL.mqtref> REF
41    %token    LPR RPR DLR SQT DQT EOF PROT SLASH FRAG QUEST STAR SSTAR 
42    %token    NAME
43    %token    MCONCL CONCL
44    %token    TRUE FALSE AND OR NOT IS
45    %token    SELECT IN WHERE USE POS USEDBY PATT UNION INTER
46    %left     OR UNION
47    %left     AND INTER
48    %nonassoc NOT
49    %start    qstr ref query
50    %type     <string>        qstr   
51    %type     <MathQL.mqtref> ref   
52    %type     <MathQL.mquery> query   
53 %%
54    prot:
55       | STR  { Some $1 }
56       | STAR { None }
57    ;
58    body:
59       |            { []            }
60       | SLASH body { MQBD :: $2    }
61       | QUEST body { MQBQ :: $2    }
62       | SSTAR body { MQBSS :: $2   }
63       | STAR body  { MQBS :: $2    }
64       | STR body   { MQBC $1 :: $2 } 
65    frag:
66       |                  { []          }
67       | SLASH SSTAR frag { MQFSS :: $3 }
68       | SLASH STAR frag  { MQFS :: $3  }
69       | SLASH STR frag   { try let i = int_of_string $2 in
70                                if i < 1 then raise Parsing.Parse_error;
71                                MQFC i :: $3
72                            with e -> raise Parsing.Parse_error
73                          }
74    ;
75    ref:
76       | prot PROT body DQT           { ($1, $3, []) }
77       | prot PROT body FRAG frag DQT { ($1, $3, $5) }
78    ;   
79    qstr:
80       | STR SQT { $1 }
81    ;
82    rvar:
83       | ID { $1 }
84    ;
85    svar:
86       | DLR ID { $2 }
87    ;
88    func:
89       | NAME { MQName }
90    ;   
91    str:
92       | MCONCL    { MQMConclusion   }
93       | CONCL     { MQConclusion    }
94       | STR       { MQCons $1       } 
95       | rvar      { MQRVar $1       }
96       | svar      { MQSVar $1       }
97       | func rvar { MQFunc ($1, $2) }
98    ;
99    boole:
100       | TRUE            { MQTrue         }
101       | FALSE           { MQFalse        }
102       | str IS str      { MQIs ($1, $3)  }
103       | NOT boole       { MQNot $2       }
104       | boole AND boole { MQAnd ($1, $3) }
105       | boole OR boole  { MQOr ($1, $3)  }
106       | LPR boole RPR   { $2             }
107    ;   
108    rlist:
109       | PATT REF                         { MQPattern $2          } 
110       | rlist UNION rlist                { MQUnion ($1, $3)      }
111       | rlist INTER rlist                { MQIntersect ($1, $3)  }
112       | USE rlist POS svar               { MQUse ($2, $4)        }
113       | USEDBY rlist POS svar            { MQUsedBy ($2, $4)     }
114       | SELECT rvar IN rlist WHERE boole { MQSelect ($2, $4, $6) }
115       | LPR rlist RPR                    { $2                    }
116    ;
117    query:
118       rlist EOF { MQList $1 }
119    ;