3 module U = UriManager;;
5 exception InvalidSuffix of string;;
6 exception InductiveTypeURIExpected;;
8 let uri_of_id_map = Hashtbl.create 53;;
10 let binders = ref [];;
12 let get_index_in_list e =
16 | he::_ when he = e -> i
17 | _::tl -> aux (i+1) tl
25 %token <UriManager.uri> CONURI
26 %token <UriManager.uri * int> INDTYURI
27 %token <UriManager.uri * int * int> INDCONURI
29 %token LPAREN RPAREN PROD LAMBDA COLON DOT SET PROP TYPE CAST IMPLICIT
30 %token LETIN FIX COFIX SEMICOLON LCURLY RCURLY CASE EOF
32 %type <Cic.term option> main
37 | EOF { raise CicTextualParser0.Eof }
41 { let uri = UriManager.string_of_uri $1 in
42 let suff = (String.sub uri (String.length uri - 3) 3) in
46 | _ -> raise (InvalidSuffix suff)
48 | INDTYURI { MutInd (fst $1, 0, snd $1) }
50 { let (uri,tyno,consno) = $1 in MutConstruct (uri, 0, tyno, consno) }
53 Rel (get_index_in_list (Name $1) !binders)
56 Hashtbl.find uri_of_id_map $1
58 | CASE LPAREN expr COLON INDTYURI SEMICOLON expr RPAREN LCURLY branches RCURLY
59 { MutCase (fst $5, 0, snd $5, $7, $3, $10) }
60 | CASE LPAREN expr COLON ID SEMICOLON expr RPAREN LCURLY branches RCURLY
62 let _ = get_index_in_list (Name $5) !binders in
63 raise InductiveTypeURIExpected
66 match Hashtbl.find uri_of_id_map $5 with
67 MutInd (uri,0,typeno) -> MutCase (uri, 0, typeno, $7, $3, $10)
68 | _ -> raise InductiveTypeURIExpected
70 | FIX ID LCURLY fixfuns RCURLY
76 | (name,_,_,_)::_ when name = $2 -> idx
77 | _::tl -> find (idx+1) tl
83 | COFIX ID LCURLY cofixfuns RCURLY
84 { let cofixfuns = $4 in
89 | (name,_,_)::_ when name = $2 -> idx
90 | _::tl -> find (idx+1) tl
96 | IMPLICIT { Implicit }
100 | LPAREN expr CAST expr RPAREN { Cast ($2,$4) }
102 | LPAREN expr expr exprlist RPAREN { Appl ([$2;$3]@$4) }
104 { binders := List.tl !binders ; Prod (fst $1, snd $1,$2) }
106 { binders := List.tl !binders ; Lambda (fst $1, snd $1,$2) }
108 { binders := List.tl !binders ; LetIn (fst $1, snd $1,$2) }
111 ID LPAREN NUM RPAREN COLON expr LETIN expr
113 | ID LPAREN NUM RPAREN COLON expr LETIN expr SEMICOLON fixfuns
114 { ($1,$3,$6,$8)::$10 }
117 ID COLON expr LETIN expr
119 | ID COLON expr LETIN expr SEMICOLON cofixfuns
123 PROD ID COLON expr DOT
124 { binders := (Name $2)::!binders ; (Cic.Name $2, $4) }
127 LAMBDA ID COLON expr DOT
128 { binders := (Name $2)::!binders ; (Cic.Name $2, $4) }
131 LAMBDA ID LETIN expr DOT
132 { binders := (Name $2)::!binders ; (Cic.Name $2, $4) }
136 | expr SEMICOLON branches { $1::$3 }
141 | expr exprlist { $1::$2 }
145 { Hashtbl.add uri_of_id_map $2 (Cic.Const ($3,0)) }
147 { Hashtbl.add uri_of_id_map $2 (Cic.MutInd (fst $3, 0, snd $3)) }
149 { let uri,indno,consno = $3 in
150 Hashtbl.add uri_of_id_map $2 (Cic.MutConstruct (uri, 0, indno ,consno))