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