]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tex_cic_textual_parser/texCicTextualParser.mly
709e23f18a65dd6207426d56068065c03701accf
[helm.git] / helm / ocaml / tex_cic_textual_parser / texCicTextualParser.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  open Cic;;
28  module U = UriManager;;
29
30  exception InvalidSuffix of string;;
31  exception InductiveTypeURIExpected;;
32  exception UnknownIdentifier of string;;
33  exception ExplicitNamedSubstitutionAppliedToRel;;
34  exception TheLeftHandSideOfAnExplicitNamedSubstitutionMustBeAVariable;;
35  
36  (* merge removing duplicates of two lists free of duplicates *)
37  let union dom1 dom2 =
38   let rec filter =
39    function
40       [] -> []
41     | he::tl ->
42        if List.mem he dom1 then filter tl else he::(filter tl)
43   in
44    dom1 @ (filter dom2)
45  ;;
46
47  let get_index_in_list e =
48   let rec aux i =
49    function
50       [] -> raise Not_found
51     | (Some he)::_ when he = e -> i
52     | _::tl -> aux (i+1) tl
53   in
54    aux 1
55  ;;
56
57  (* Returns the first meta whose number is above the *)
58  (* number of the higher meta.                       *)
59  (*CSC: cut&pasted from proofEngine.ml *)
60  let new_meta () =
61   let rec aux =
62    function
63       None,[] -> 1
64     | Some n,[] -> n
65     | None,(n,_,_)::tl -> aux (Some n,tl)
66     | Some m,(n,_,_)::tl -> if n > m then aux (Some n,tl) else aux (Some m,tl)
67   in
68    1 + aux (None,!TexCicTextualParser0.metasenv)
69  ;;
70
71  (* identity_relocation_list_for_metavariable i canonical_context         *)
72  (* returns the identity relocation list, which is the list [1 ; ... ; n] *)
73  (* where n = List.length [canonical_context]                             *)
74  (*CSC: ma mi basta la lunghezza del contesto canonico!!!*)
75  (*CSC: cut&pasted from proofEngine.ml *)
76  let identity_relocation_list_for_metavariable canonical_context =
77   let canonical_context_length = List.length canonical_context in
78    let rec aux =
79     function
80        (_,[]) -> []
81      | (n,None::tl) -> None::(aux ((n+1),tl))
82      | (n,_::tl) -> (Some (Cic.Rel n))::(aux ((n+1),tl))
83    in
84     aux (1,canonical_context)
85  ;;
86
87  let deoptionize_exp_named_subst =
88   function
89      None -> [], (function _ -> [])
90    | Some (dom,mk_exp_named_subst) -> dom,mk_exp_named_subst
91  ;;
92
93  let term_of_con_uri uri exp_named_subst =
94   Const (uri,exp_named_subst)
95  ;;
96
97  let term_of_var_uri uri exp_named_subst =
98   Var (uri,exp_named_subst)
99  ;;
100
101  let term_of_indty_uri (uri,tyno) exp_named_subst =
102   MutInd (uri, tyno, exp_named_subst)
103  ;;
104
105  let term_of_indcon_uri (uri,tyno,consno) exp_named_subst =
106   MutConstruct (uri, tyno, consno, exp_named_subst)
107  ;;
108
109  let term_of_uri uri =
110   match uri with
111      CicTextualParser0.ConUri uri ->
112       term_of_con_uri uri
113    | CicTextualParser0.VarUri uri ->
114       term_of_var_uri uri
115    | CicTextualParser0.IndTyUri (uri,tyno) ->
116       term_of_indty_uri (uri,tyno) 
117    | CicTextualParser0.IndConUri (uri,tyno,consno) ->
118       term_of_indcon_uri (uri,tyno,consno)
119  ;;
120
121  let var_uri_of_id id interp =
122   let module CTP0 = CicTextualParser0 in
123    match interp (CicTextualParser0.Id id) with
124       None -> raise (UnknownIdentifier id)
125     | Some (CTP0.Uri (CTP0.VarUri uri)) -> uri
126     | Some _ -> raise TheLeftHandSideOfAnExplicitNamedSubstitutionMustBeAVariable
127  ;;
128
129  let indty_uri_of_id id interp =
130   let module CTP0 = CicTextualParser0 in
131    match interp (CicTextualParser0.Id id) with
132       None -> raise (UnknownIdentifier id)
133     | Some (CTP0.Uri (CTP0.IndTyUri (uri,tyno))) -> (uri,tyno)
134     | Some _ -> raise InductiveTypeURIExpected
135  ;;
136
137  let mk_implicit () =
138   let newmeta = new_meta () in
139    let new_canonical_context = [] in
140     let irl =
141      identity_relocation_list_for_metavariable new_canonical_context
142     in
143      TexCicTextualParser0.metasenv :=
144       [newmeta, new_canonical_context, Sort Type ;
145        newmeta+1, new_canonical_context, Meta (newmeta,irl);
146        newmeta+2, new_canonical_context, Meta (newmeta+1,irl)
147       ] @ !TexCicTextualParser0.metasenv ;
148      [], function _ -> Meta (newmeta+2,irl)
149  ;;
150 %}
151 %token <string> ID
152 %token <int> META
153 %token <int> NUM
154 %token <int> RNUM
155 %token <UriManager.uri> CONURI
156 %token <UriManager.uri> VARURI
157 %token <UriManager.uri * int> INDTYURI
158 %token <UriManager.uri * int * int> INDCONURI
159 %token LPAREN RPAREN PROD LAMBDA COLON DOT SET PROP TYPE CAST IMPLICIT NONE
160 %token LETIN FIX COFIX SEMICOLON LCURLY RCURLY CASE ARROW LBRACKET RBRACKET EOF
161 %token DOLLAR
162 %token RPLUS RMINUS RTIMES RDIV
163 %token PLUS MINUS TIMES EQT EQ
164 %right ARROW
165 %nonassoc EQ EQT
166 %left PLUS MINUS RPLUS RMINUS
167 %left TIMES RTIMES RDIV
168 %start main
169 %type <CicTextualParser0.interpretation_domain_item list * (CicTextualParser0.interpretation -> Cic.term)> main
170 %%
171 main:
172  | EOF { raise CicTextualParser0.Eof } /* FG: was never raised */
173  | DOLLAR DOLLAR EOF {raise CicTextualParser0.Eof }
174  | DOLLAR DOLLAR DOLLAR DOLLAR EOF {raise CicTextualParser0.Eof }
175  | expr EOF { $1 }
176  | DOLLAR expr DOLLAR EOF { $2 }
177  | DOLLAR DOLLAR expr DOLLAR DOLLAR EOF { $3 }
178  | expr SEMICOLON { $1 } /*  FG: to read several terms in a row
179                           *  Do we need to clear some static variables? 
180                           */
181 ;
182 expr2:
183  | RNUM
184    { [], function interp ->
185       let rec cic_real_of_real =
186        function
187           0 ->
188            Cic.Const
189             (UriManager.uri_of_string
190               "cic:/Coq/Reals/Rdefinitions/R0.con",[])
191         | 1 ->
192            Cic.Const
193             (UriManager.uri_of_string "cic:/Coq/Reals/Rdefinitions/R1.con",[])
194         | n ->
195           Cic.Appl
196            [ Cic.Const
197                (UriManager.uri_of_string
198                   "cic:/Coq/Reals/Rdefinitions/Rplus.con",[]) ;
199              Cic.Const (UriManager.uri_of_string
200               "cic:/Coq/Reals/Rdefinitions/R1.con",[]);
201              cic_real_of_real (n - 1)
202            ]
203       in
204        cic_real_of_real $1
205    }
206  | NUM
207    { [], function interp ->
208       let rec cic_int_of_int =
209        function
210           0 ->
211            Cic.MutConstruct
212             (UriManager.uri_of_string "cic:/Coq/Init/Datatypes/nat.ind",
213              0,1,[])
214         | n ->
215           Cic.Appl
216            [ Cic.MutConstruct
217               (UriManager.uri_of_string "cic:/Coq/Init/Datatypes/nat.ind",
218                0,2,[]) ;
219              cic_int_of_int (n - 1)
220            ]
221       in
222        cic_int_of_int $1
223    }
224  | expr2 RPLUS expr2
225    { let dom1,mk_expr1 = $1 in
226      let dom2,mk_expr2 = $3 in
227       let dom = union dom1 dom2 in
228        dom, function interp ->
229         Cic.Appl
230          [Cic.Const
231            (UriManager.uri_of_string
232               "cic:/Coq/Reals/Rdefinitions/Rplus.con",[]) ;
233           (mk_expr1 interp) ;
234           (mk_expr2 interp)
235          ]
236    }
237  | expr2 RMINUS expr2
238    { let dom1,mk_expr1 = $1 in
239      let dom2,mk_expr2 = $3 in
240       let dom = union dom1 dom2 in
241        dom, function interp ->
242         Cic.Appl
243          [Cic.Const
244            (UriManager.uri_of_string
245               "cic:/Coq/Reals/Rdefinitions/Rminus.con",[]) ;
246           (mk_expr1 interp) ;
247           (mk_expr2 interp)
248          ]
249    }
250  | expr2 RTIMES expr2
251    { let dom1,mk_expr1 = $1 in
252      let dom2,mk_expr2 = $3 in
253       let dom = union dom1 dom2 in
254        dom, function interp ->
255         Cic.Appl
256          [Cic.Const
257            (UriManager.uri_of_string
258               "cic:/Coq/Reals/Rdefinitions/Rmult.con",[]) ;
259           (mk_expr1 interp) ;
260           (mk_expr2 interp)
261          ]
262    }
263  | expr2 RDIV expr2
264    { let dom1,mk_expr1 = $1 in
265      let dom2,mk_expr2 = $3 in
266       let dom = union dom1 dom2 in
267        dom, function interp ->
268         Cic.Appl
269          [Cic.Const
270            (UriManager.uri_of_string
271               "cic:/Coq/Reals/Rdefinitions/Rdiv.con",[]) ;
272           (mk_expr1 interp) ;
273           (mk_expr2 interp)
274          ]
275    }
276  | expr2 PLUS expr2
277    { let dom1,mk_expr1 = $1 in
278      let dom2,mk_expr2 = $3 in
279       let dom = union dom1 dom2 in
280        dom, function interp ->
281         Cic.Appl
282          [Cic.Const
283            (UriManager.uri_of_string "cic:/Coq/Init/Peano/plus.con",[]) ;
284           (mk_expr1 interp) ;
285           (mk_expr2 interp)
286          ]
287    }
288  | expr2 MINUS expr2
289    { let dom1,mk_expr1 = $1 in
290      let dom2,mk_expr2 = $3 in
291       let dom = union dom1 dom2 in
292        dom, function interp ->
293         Cic.Appl
294          [Cic.Const
295            (UriManager.uri_of_string "cic:/Coq/Arith/Minus/minus.con",[]) ;
296           (mk_expr1 interp) ;
297           (mk_expr2 interp)
298          ]
299    }
300  | expr2 TIMES expr2
301    { let dom1,mk_expr1 = $1 in
302      let dom2,mk_expr2 = $3 in
303       let dom = union dom1 dom2 in
304        dom, function interp ->
305         Cic.Appl
306          [Cic.Const
307            (UriManager.uri_of_string "cic:/Coq/Init/Peano/mult.con",[]) ;
308           (mk_expr1 interp) ;
309           (mk_expr2 interp)
310          ]
311    }
312  | expr2 EQT expr2
313    { let dom1,mk_expr1 = $1 in
314      let dom2,mk_expr2 = $3 in
315      let dom3,mk_expr3 = mk_implicit () in
316       let dom = union dom1 (union dom2 dom3) in
317        dom, function interp ->
318         Cic.Appl
319          [Cic.MutInd
320            (UriManager.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind",0,[]) ;
321           (mk_expr3 interp) ;
322           (mk_expr1 interp) ;
323           (mk_expr2 interp)
324          ]
325    }
326  | expr2 EQ expr2
327    { let dom1,mk_expr1 = $1 in
328      let dom2,mk_expr2 = $3 in
329      let dom3,mk_expr3 = mk_implicit () in
330       let dom = union dom1 (union dom2 dom3) in
331        dom, function interp ->
332         Cic.Appl
333          [Cic.MutInd
334            (UriManager.uri_of_string "cic:/Coq/Init/Logic/eq.ind",0,[]) ;
335           (mk_expr3 interp) ;
336           (mk_expr1 interp) ;
337           (mk_expr2 interp)
338          ]
339    }
340  | CONURI exp_named_subst
341    { let dom,mk_exp_named_subst = deoptionize_exp_named_subst $2 in
342       dom, function interp -> term_of_con_uri $1 (mk_exp_named_subst interp)
343    }
344  | VARURI exp_named_subst
345    { let dom,mk_exp_named_subst = deoptionize_exp_named_subst $2 in
346       dom, function interp -> term_of_var_uri $1 (mk_exp_named_subst interp)
347    }
348  | INDTYURI exp_named_subst
349    { let dom,mk_exp_named_subst = deoptionize_exp_named_subst $2 in
350       dom, function interp -> term_of_indty_uri $1 (mk_exp_named_subst interp)
351    }
352  | INDCONURI exp_named_subst
353    { let dom,mk_exp_named_subst = deoptionize_exp_named_subst $2 in
354       dom, function interp -> term_of_indcon_uri $1 (mk_exp_named_subst interp)
355    }
356  | ID exp_named_subst
357    { try
358       let res =
359        Rel (get_index_in_list (Name $1) !TexCicTextualParser0.binders)
360       in
361        (match $2 with
362            None -> ([], function _ -> res)
363          | Some _ -> raise (ExplicitNamedSubstitutionAppliedToRel)
364        )
365      with
366       Not_found ->
367        let dom1,mk_exp_named_subst = deoptionize_exp_named_subst $2 in
368         let dom = union dom1 [CicTextualParser0.Id $1] in
369          dom,
370           function interp ->
371            match interp (CicTextualParser0.Id $1) with
372               None  -> raise (UnknownIdentifier $1)
373             | Some (CicTextualParser0.Uri uri) ->
374                term_of_uri uri (mk_exp_named_subst interp)
375             | Some CicTextualParser0.Implicit ->
376                (*CSC: not very clean; to maximize code reusage *)
377                snd (mk_implicit ()) ""
378             | Some (CicTextualParser0.Term mk_term) ->
379                (mk_term interp)
380    }
381  | CASE LPAREN expr COLON INDTYURI SEMICOLON expr RPAREN LCURLY branches RCURLY
382     { let dom1,mk_expr1 = $3 in
383       let dom2,mk_expr2 = $7 in
384       let dom3,mk_expr3 = $10 in
385        let dom = union dom1 (union dom2 dom3) in
386         dom,
387         function interp ->
388          MutCase
389           (fst $5,snd $5,(mk_expr2 interp),(mk_expr1 interp),(mk_expr3 interp))
390     }
391  | CASE LPAREN expr COLON ID SEMICOLON expr RPAREN LCURLY branches RCURLY
392     { let dom1,mk_expr1 = $3 in
393       let dom2,mk_expr2 = $7 in
394       let dom3,mk_expr3 = $10 in
395        let dom =
396         union [CicTextualParser0.Id $5] (union dom1 (union dom2 dom3))
397        in
398         dom,
399         function interp ->
400          let uri,typeno = indty_uri_of_id $5 interp in
401           MutCase
402            (uri,typeno,(mk_expr2 interp),(mk_expr1 interp),
403              (mk_expr3 interp))
404     }
405  | fixheader LCURLY exprseplist RCURLY
406     { let dom1,foo,ids_and_indexes,mk_types = $1 in
407       let dom2,mk_exprseplist = $3 in
408        let dom = union dom1 dom2 in
409         for i = 1 to List.length ids_and_indexes do
410          TexCicTextualParser0.binders := List.tl !TexCicTextualParser0.binders
411         done ;
412         dom,
413          function interp ->
414           let types = mk_types interp in
415           let fixfunsbodies = (mk_exprseplist interp) in
416            let idx =
417             let rec find idx =
418              function
419                 [] -> raise Not_found
420               | (name,_)::_  when name = foo -> idx
421               | _::tl -> find (idx+1) tl
422             in
423              find 0 ids_and_indexes
424            in
425             let fixfuns =
426              List.map2 (fun ((name,recindex),ty) bo -> (name,recindex,ty,bo))
427               (List.combine ids_and_indexes types) fixfunsbodies
428             in
429              Fix (idx,fixfuns)
430     }
431  | cofixheader LCURLY exprseplist RCURLY
432     { let dom1,foo,ids,mk_types = $1 in
433       let dom2,mk_exprseplist = $3 in
434        let dom = union dom1 dom2 in
435         dom,
436          function interp ->
437           let types = mk_types interp in
438           let fixfunsbodies = (mk_exprseplist interp) in
439            let idx =
440             let rec find idx =
441              function
442                 [] -> raise Not_found
443               | name::_  when name = foo -> idx
444               | _::tl -> find (idx+1) tl
445             in
446              find 0 ids
447            in
448             let fixfuns =
449              List.map2 (fun (name,ty) bo -> (name,ty,bo))
450               (List.combine ids types) fixfunsbodies
451             in
452              for i = 1 to List.length fixfuns do
453               TexCicTextualParser0.binders :=
454                List.tl !TexCicTextualParser0.binders
455              done ;
456              CoFix (idx,fixfuns)
457     }
458  | IMPLICIT
459     { mk_implicit () }
460  | SET  { [], function _ -> Sort Set }
461  | PROP { [], function _ -> Sort Prop }
462  | TYPE { [], function _ -> Sort Type }
463  | LPAREN expr CAST expr RPAREN
464     { let dom1,mk_expr1 = $2 in
465       let dom2,mk_expr2 = $4 in
466        let dom = union dom1 dom2 in
467         dom, function interp -> Cast ((mk_expr1 interp),(mk_expr2 interp))
468     }
469  | META LBRACKET substitutionlist RBRACKET
470     { let dom,mk_substitutionlist = $3 in
471        dom, function interp -> Meta ($1, mk_substitutionlist interp)
472     } 
473  | LPAREN expr exprlist RPAREN
474     { let length,dom2,mk_exprlist = $3 in
475        match length with
476           0 -> $2
477         | _ ->
478           let dom1,mk_expr1 = $2 in
479            let dom = union dom1 dom2 in
480             dom,
481              function interp ->
482               Appl ((mk_expr1 interp)::(mk_exprlist interp))
483     }
484 ;
485 exp_named_subst :
486     { None }
487  | LCURLY named_substs RCURLY
488     { Some $2 }
489 ;
490 named_substs :
491    VARURI LETIN expr2
492     { let dom,mk_expr = $3 in
493        dom, function interp -> [$1, mk_expr interp] }
494  | ID LETIN expr2
495     { let dom1,mk_expr = $3 in
496        let dom = union [CicTextualParser0.Id $1] dom1 in
497         dom, function interp -> [var_uri_of_id $1 interp, mk_expr interp] }
498  | VARURI LETIN expr2 SEMICOLON named_substs
499     { let dom1,mk_expr = $3 in
500       let dom2,mk_named_substs = $5 in
501        let dom = union dom1 dom2 in
502         dom, function interp -> ($1, mk_expr interp)::(mk_named_substs interp)
503     }
504  | ID LETIN expr2 SEMICOLON named_substs
505     { let dom1,mk_expr = $3 in
506       let dom2,mk_named_substs = $5 in
507        let dom = union [CicTextualParser0.Id $1] (union dom1 dom2) in
508         dom,
509          function interp ->
510           (var_uri_of_id $1 interp, mk_expr interp)::(mk_named_substs interp)
511     }
512 ;
513 expr :
514    pihead expr
515     { TexCicTextualParser0.binders := List.tl !TexCicTextualParser0.binders ;
516       let dom1,mk_expr1 = snd $1 in
517       let dom2,mk_expr2 = $2 in
518        let dom = union dom1 dom2 in
519         dom, function interp -> Prod (fst $1, mk_expr1 interp, mk_expr2 interp)
520     }
521  | lambdahead expr
522     { TexCicTextualParser0.binders := List.tl !TexCicTextualParser0.binders ;
523       let dom1,mk_expr1 = snd $1 in
524       let dom2,mk_expr2 = $2 in
525        let dom = union dom1 dom2 in
526         dom,function interp -> Lambda (fst $1, mk_expr1 interp, mk_expr2 interp)
527     }
528  | letinhead expr
529     { TexCicTextualParser0.binders := List.tl !TexCicTextualParser0.binders ;
530       let dom1,mk_expr1 = snd $1 in
531       let dom2,mk_expr2 = $2 in
532        let dom = union dom1 dom2 in
533         dom, function interp -> LetIn (fst $1, mk_expr1 interp, mk_expr2 interp)
534     }
535  | expr2
536     { $1 }
537 ;
538 fixheader:
539    FIX ID LCURLY fixfunsdecl RCURLY
540     { let dom,ids_and_indexes,mk_types = $4 in
541        let bs =
542         List.rev_map (function (name,_) -> Some (Name name)) ids_and_indexes
543        in
544         TexCicTextualParser0.binders := bs@(!TexCicTextualParser0.binders) ;
545         dom, $2, ids_and_indexes, mk_types
546     }
547 ;
548 fixfunsdecl:
549    ID LPAREN NUM RPAREN COLON expr
550     { let dom,mk_expr = $6 in
551        dom, [$1,$3], function interp -> [mk_expr interp]
552     }
553  | ID LPAREN NUM RPAREN COLON expr SEMICOLON fixfunsdecl
554     { let dom1,mk_expr = $6 in
555       let dom2,ids_and_indexes,mk_types = $8 in
556        let dom = union dom1 dom2 in
557         dom, ($1,$3)::ids_and_indexes,
558          function interp -> (mk_expr interp)::(mk_types interp)
559     }
560 ;
561 cofixheader:
562    COFIX ID LCURLY cofixfunsdecl RCURLY
563     { let dom,ids,mk_types = $4 in
564        let bs =
565         List.rev_map (function name -> Some (Name name)) ids
566        in
567         TexCicTextualParser0.binders := bs@(!TexCicTextualParser0.binders) ;
568         dom, $2, ids, mk_types
569     }
570 ;
571 cofixfunsdecl:
572    ID COLON expr
573     { let dom,mk_expr = $3 in
574        dom, [$1], function interp -> [mk_expr interp]
575     }
576  | ID COLON expr SEMICOLON cofixfunsdecl
577     { let dom1,mk_expr = $3 in
578       let dom2,ids,mk_types = $5 in
579        let dom = union dom1 dom2 in
580         dom, $1::ids,
581          function interp -> (mk_expr interp)::(mk_types interp)
582     }
583 ;
584 pihead:
585    PROD ID COLON expr DOT
586     { TexCicTextualParser0.binders :=
587        (Some (Name $2))::!TexCicTextualParser0.binders;
588       let dom,mk_expr = $4 in
589        Cic.Name $2, (dom, function interp -> mk_expr interp)
590     }
591  | expr2 ARROW
592    { TexCicTextualParser0.binders :=
593       (Some Anonymous)::!TexCicTextualParser0.binders ;
594      let dom,mk_expr = $1 in
595       Anonymous, (dom, function interp -> mk_expr interp)
596    }
597  | PROD ID DOT
598     { TexCicTextualParser0.binders :=
599        (Some (Name $2))::!TexCicTextualParser0.binders;
600       let newmeta = new_meta () in
601        let new_canonical_context = [] in
602         let irl =
603          identity_relocation_list_for_metavariable new_canonical_context
604         in
605          TexCicTextualParser0.metasenv :=
606           [newmeta, new_canonical_context, Sort Type ;
607            newmeta+1, new_canonical_context, Meta (newmeta,irl)
608           ] @ !TexCicTextualParser0.metasenv ;
609          Cic.Name $2, ([], function _ -> Meta (newmeta+1,irl))
610     }
611 ;
612 lambdahead:
613    LAMBDA ID COLON expr DOT
614     { TexCicTextualParser0.binders :=
615        (Some (Name $2))::!TexCicTextualParser0.binders;
616       let dom,mk_expr = $4 in
617        Cic.Name $2, (dom, function interp -> mk_expr interp)
618     }
619  | LAMBDA ID DOT
620     { TexCicTextualParser0.binders :=
621        (Some (Name $2))::!TexCicTextualParser0.binders;
622       let newmeta = new_meta () in
623        let new_canonical_context = [] in
624         let irl =
625          identity_relocation_list_for_metavariable new_canonical_context
626         in
627          TexCicTextualParser0.metasenv :=
628           [newmeta, new_canonical_context, Sort Type ;
629            newmeta+1, new_canonical_context, Meta (newmeta,irl)
630           ] @ !TexCicTextualParser0.metasenv ;
631          Cic.Name $2, ([], function _ -> Meta (newmeta+1,irl))
632     }
633 ;
634 letinhead:
635   LAMBDA ID LETIN expr DOT
636    { TexCicTextualParser0.binders :=
637       (Some (Name $2))::!TexCicTextualParser0.binders ;
638      let dom,mk_expr = $4 in
639       Cic.Name $2, (dom, function interp -> mk_expr interp)
640    }
641 ;
642 branches:
643     { [], function _ -> [] }
644  | expr SEMICOLON branches
645     { let dom1,mk_expr = $1 in
646       let dom2,mk_branches = $3 in
647        let dom = union dom1 dom2 in
648         dom, function interp -> (mk_expr interp)::(mk_branches interp)
649     }
650  | expr
651     { let dom,mk_expr = $1 in
652        dom, function interp -> [mk_expr interp]
653     }
654 ;
655 exprlist:
656     
657     { 0, [], function _ -> [] }
658  | expr exprlist
659     { let dom1,mk_expr = $1 in
660       let length,dom2,mk_exprlist = $2 in
661        let dom = union dom1 dom2 in
662         length+1, dom, function interp -> (mk_expr interp)::(mk_exprlist interp)
663     }
664 ;
665 exprseplist:
666    expr
667     { let dom,mk_expr = $1 in
668        dom, function interp -> [mk_expr interp]
669     }
670  | expr SEMICOLON exprseplist
671     { let dom1,mk_expr = $1 in
672       let dom2,mk_exprseplist = $3 in
673        let dom = union dom1 dom2 in
674         dom, function interp -> (mk_expr interp)::(mk_exprseplist interp)
675     }
676 ;
677 substitutionlist:
678     { [], function _ -> [] }
679  | expr SEMICOLON substitutionlist
680     { let dom1,mk_expr = $1 in
681       let dom2,mk_substitutionlist = $3 in
682        let dom = union dom1 dom2 in
683         dom,
684          function interp ->(Some (mk_expr interp))::(mk_substitutionlist interp)
685     }
686  | NONE SEMICOLON substitutionlist
687     { let dom,mk_exprsubstitutionlist = $3 in
688        dom, function interp -> None::(mk_exprsubstitutionlist interp)
689     }