]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/src/text/txtParser.mly
- initial support for abstractions with explicit levels
[helm.git] / helm / software / lambda-delta / src / text / txtParser.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    module G = Options
28    module N = Level
29    module T = Txt
30    
31    let _ = Parsing.set_trace !G.debug_parser
32 %}
33    %token <int> IX
34    %token <string> ID STR
35    %token OP CP OB CB OA CA FS CN CM EQ STAR HASH PLUS TE WTO STO CT
36    %token GRAPH DECL AX CONG DEF TH GEN REQ OPEN CLOSE SORTS EOF
37
38    %start entry
39    %type <Txt.command option> entry
40
41    %nonassoc CP CB CA
42    %right WTO STO
43 %%
44    hash:
45       |      {}
46       | HASH {}
47    ;
48    fs:
49       |    {}
50       | FS {}
51    ;
52    comment:
53       |     { "" }
54       | STR { $1 }
55    ;
56    ids:
57       | ID        { [$1]     }
58       | ID CM ids { $1 :: $3 }
59    ;
60    sort:
61       | ID    { None, $1    }
62       | IX ID { Some $1, $2 }
63    ;
64    sorts:
65       | sort          { [$1]     }
66       | sort CM sorts { $1 :: $3 }
67    ;
68    level:
69       |       { N.infinite }
70       | CT IX { N.finite $2}
71    ;
72
73    abst:
74       | ID CN term { $1, true, $3  }
75       | TE term    { "", false, $2 }
76       | ID TE term { $1, false, $3 }
77    ;
78    abbr:
79       | ID EQ term { $1, $3 }
80    ;
81    absts:
82       | abst          { [$1]     }
83       | abst CM absts { $1 :: $3 }
84    ;
85    abbrs:
86       | abbr          { [$1]     }
87       | abbr CM abbrs { $1 :: $3 }
88    ;   
89    binder: 
90       | absts { T.Abst $1 }
91       | abbrs { T.Abbr $1 }
92       | ids   { T.Void $1 }
93    ;      
94    atom:
95       | STAR IX          { T.Sort $2         }
96       | STAR ID          { T.NSrt $2         }
97       | hash IX          { T.LRef ($2, 0)    }
98       | hash IX PLUS IX  { T.LRef ($2, $4)   }
99       | ID               { T.NRef $1         }
100       | HASH ID          { T.NRef $2         }
101       | atom OP term CP  { T.Inst ($1, [$3]) }
102       | atom OP terms CP { T.Inst ($1, $3)   }
103    ;
104    term:
105       | atom                       { $1                             }
106       | OA term CA fs term         { T.Cast ($2, $5)                }
107       | OP term CP fs term         { T.Appl ([$2], $5)              }
108       | OP terms CP fs term        { T.Appl ($2, $5)                }
109       | OB binder CB level fs term { T.Bind ($4, $2, $6)            }
110       | term WTO level term        { T.Impl ($3, false, "", $1, $4) }
111       | ID TE term WTO level term  { T.Impl ($5, false, $1, $3, $6) }
112       | term STO level term        { T.Impl ($3, true, "", $1, $4)  }
113       | ID TE term STO level term  { T.Impl ($5, true, $1, $3, $6)  }
114       | OP term CP                 { $2                             }
115    ;
116    terms:
117       | term CM term  { [$1; $3] }
118       | term CM terms { $1 :: $3 }
119    ;
120    
121    decl:
122       | DECL { T.Decl }
123       | AX   { T.Ax   }
124       | CONG { T.Cong }
125    ;
126    def:   
127       | DEF  { T.Def } 
128       | TH   { T.Th  }
129    ;
130    xentity:
131       | GRAPH ID
132          { T.Graph $2                                 }
133       | decl level comment ID CN term
134          { T.Entity ($1, $2, $4, $3, $6)              }
135       | def level comment ID EQ term
136          { T.Entity ($1, $2, $4, $3, $6)              }
137       | def level comment ID EQ term CN term
138          { T.Entity ($1, $2, $4, $3, T.Cast ($8, $6)) }
139       | GEN term
140          { T.Generate [$2]                            }
141       | GEN terms
142          { T.Generate $2                              }      
143       | REQ ids
144          { T.Require $2                               }
145       | OPEN ID                           
146          { T.Section (Some $2)                        }
147       | CLOSE                             
148          { T.Section None                             }
149       | SORTS sorts
150          { T.Sorts $2                                 }
151    ;
152    start: 
153       | GRAPH {} | decl {} | def {} | GEN {} |
154       | REQ {} | OPEN {} | CLOSE {} | SORTS {} | EOF {}
155    ;
156    entry:
157       | xentity start { Some $1 }
158       | EOF           { None    }
159    ;