1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
(********************************************************************)
(* *)
(* The Why3 Verification Platform / The Why3 Development Team *)
(* Copyright 2010-2025 -- Inria - CNRS - Paris-Saclay University *)
(* *)
(* This software is distributed under the terms of the GNU Lesser *)
(* General Public License version 2.1, with the special exception *)
(* on linking described in file LICENSE. *)
(********************************************************************)
%{
open Why3
open Coma_syntax
let mk_pexpr d loc = { pexpr_desc = d; pexpr_loc = Loc.extract loc }
let mk_defn d loc = { pdefn_desc = d; pdefn_loc = Loc.extract loc }
%}
%token BANG QUESTION LEFTMINBRC RIGHTMINBRC
%start <Coma_syntax.pfile> top_level
%start <unit> dummy
%%
top_level:
| coma_top_lvl* EOF
{ let loc = floc $startpos $startpos in
[{id_str = "Coma"; id_ats = []; id_loc = loc}, $1] }
| coma_module+ EOF
{ $1 }
coma_module:
| MODULE attrs(uident_nq) coma_top_lvl* END
{ $2, $3 }
uses:
| USE EXPORT tqualid
{ Puseexport $3 }
| USE boption(IMPORT) n = tqualid q = option(preceded(AS, uident))
{ let loc = floc $startpos $endpos in
if $2 && q = None then Loc.warning warn_redundant_import ~loc
"the keyword `import' is redundant here and can be omitted";
(Puseimport ($2, n, q) ) }
coma_top_lvl:
| LET ioption(REC) separated_nonempty_list(WITH, defn(EQUAL))
{ Blo $3 }
| pure_decl
{ Mlw $1 }
| meta_decl
{ Mlw $1 }
| uses
{ Use $1 }
defn(X):
| id=attrs(lword_nq) w=prewrites p=coma_params X e=coma_prog
{ mk_defn { pdefn_name = id; pdefn_writes = w;
pdefn_params = p; pdefn_body = e } $loc }
coma_prog:
| e=coma_expr bl=coma_bloc*
{ List.fold_left (fun acc b -> (b acc)) e bl }
coma_bloc:
| LEFTSQ option(BAR) l=separated_nonempty_list(BAR, coma_let) RIGHTSQ
{ fun e -> (mk_pexpr (PElet (e, l)) $loc) }
| LEFTSQ option(BAR) dl=separated_nonempty_list(BAR, defn(EQUAL)) RIGHTSQ
{ fun e -> (mk_pexpr (PEdef (e, false, dl)) $loc) }
| LEFTSQ option(BAR) dl=separated_nonempty_list(BAR, defn(ARROW)) RIGHTSQ
{ fun e -> (mk_pexpr (PEdef (e, true, dl)) $loc) }
coma_let:
| AMP id=attrs(lword_nq) ty=oftyp EQUAL t=term
{ id, t, ty, true }
| id=attrs(lword_nq) ty=oftyp EQUAL t=term
{ id, t, ty, false }
coma_set:
| AMP id=lword LARROW t=term { id, t }
coma_expr:
| d = coma_desc
{ mk_pexpr d $loc }
coma_expr_no_assert:
| d = coma_desc_no_assert
{ mk_pexpr d $loc }
coma_desc_no_assert:
| LEFTSQ l=separated_nonempty_list(BAR, coma_set) RIGHTSQ e=coma_expr
{ PEset (e, l) }
| LEFTPAR BANG e=coma_prog RIGHTPAR
{ PEbox e }
| LEFTPAR QUESTION e=coma_prog RIGHTPAR
{ PEwox e }
| e=coma_expr2 al=coma_arg* at=coma_dot
{ let app e a = mk_pexpr (PEapp (e, a)) $loc in
let e = List.fold_left app e al in
let e = List.fold_left app e at in
e.pexpr_desc }
coma_named_term:
| s=STRING BAR t=term { name_term (Some (mk_id s $startpos(s) $endpos(s))) "Assert" t }
| t=term { name_term None "Assert" t }
coma_assert_assume:
| LEFTBRC t=coma_named_term RIGHTBRC
{ t, true }
| LEFTMINBRC t=coma_named_term RIGHTMINBRC
{ t, false }
coma_desc:
| l=nonempty_list(coma_assert_assume) e=coma_expr_no_assert
{ PEcut (l, e) }
| coma_desc_no_assert
{ $1 }
coma_expr2:
| d = coma_desc2
{ mk_pexpr d $loc }
coma_desc2:
| x=lqword
{ PEsym x }
| ANY
{ PEany }
| LEFTPAR c=coma_closure(coma_prog) RIGHTPAR
{ c.pexpr_desc }
| LEFTPAR e=coma_prog RIGHTPAR
{ e.pexpr_desc }
coma_closure(X):
| FUN p=coma_param+ ARROW e=X
{ let d = PElam (List.flatten p, e) in
mk_pexpr d $loc }
| ARROW e=X
{ let d = PElam ([], e) in
mk_pexpr d $loc }
%inline prewrites:
| LEFTSQ w=lword* RIGHTSQ
{ w }
| (* epsilon *)
{ [] }
coma_arg:
| LT ty=ty GT
{ PAt ty }
| LEFTBRC t=term RIGHTBRC
{ PAv t }
| AMP x=lword
{ PAr x }
| LEFTPAR e=coma_prog RIGHTPAR
{ PAc e }
| li=lqword
{ let d = mk_pexpr (PEsym li) $loc in
PAc d }
| LEFTPAR c=coma_closure(coma_prog) RIGHTPAR
{ PAc c }
coma_dot:
| (* epsilon *) { [] }
| DOT coma_expr { [PAc $2] }
| DOT coma_closure(coma_expr) { [PAc $2] }
coma_params:
| pl=coma_param*
{ (List.flatten pl) }
coma_params_depth:
| pl=coma_param_depth*
{ (List.flatten pl) }
coma_tvar:
| x=quote_lident
{ PPt x }
coma_param_common:
| LT l=coma_tvar* GT
{ l }
| LEFTPAR lid=coma_binder+ t=oftyp RIGHTPAR
{ List.map (fun (b,id) -> if b then PPr (id,t) else PPv (id,t)) lid }
| LEFTPAR id=attrs(lword_nq) w=prewrites p=coma_params_depth RIGHTPAR
{ [PPc (id, w, p)] }
| LEFTBRC DOTDOT RIGHTBRC
{ [PPo] }
| LEFTBRC RIGHTBRC
{ [PPb] }
| LEFTSQ l=separated_nonempty_list(BAR, coma_let) RIGHTSQ
{ [PPl l] }
coma_param:
| coma_param_common { $1 }
| LEFTBRC t=coma_named_term RIGHTBRC
{ [PPa (t,true)] }
| LEFTMINBRC t=coma_named_term RIGHTMINBRC
{ [PPa (t,false)] }
coma_param_depth:
| coma_param_common { $1 }
| LEFTBRC t=coma_named_term RIGHTBRC
{ [PPa (t,true)] }
| LEFTMINBRC t=coma_named_term RIGHTMINBRC
{ [PPa (t,false)] }
coma_binder:
| id=attrs(lword_nq)
{ false, id }
| AMP id=attrs(lword_nq)
{ true, id }
oftyp:
| COLON t=ty { t }
lqword:
| lword { Qident $1 }
| uqualid DOT lword { Qdot ($1, $3) }
lword:
| lident { $1 }
| lkeyword { mk_id $1 $startpos $endpos }
lword_nq:
| lident_nq { $1 }
| lkeyword { mk_id $1 $startpos $endpos }
lkeyword:
| ABSURD { "absurd" }
| RETURN { "return" }
| ABSTRACT { "abstract" }
| ALIAS { "alias" }
(* | ANY { "any" } *)
| AS { "as" }
| ASSERT { "assert" }
| ASSUME { "assume" }
| AT { "at" }
(* | AXIOM { "axiom" } *)
| BEGIN { "begin" }
| BREAK { "break" }
| BY { "by" }
| CHECK { "check" }
| CLONE { "clone" }
(* | COINDUCTIVE { "coinductive" } *)
(* | CONSTANT { "constant" } *)
| CONTINUE { "continue" }
| DIVERGES { "diverges" }
| DO { "do" }
| DONE { "done" }
| DOWNTO { "downto" }
| ELSE { "else" }
(* | END { "end" } *)
| ENSURES { "ensures" }
| EPSILON { "epsilon" }
| EXCEPTION { "exception" }
| EXISTS { "exists" }
| EXPORT { "export" }
| FALSE { "false" }
| FOR { "for" }
| FORALL { "forall" }
(* | FUN { "fun" } *)
(* | FUNCTION { "function" } *)
| GHOST { "ghost" }
(* | GOAL { "goal" } *)
| IF { "if" }
| IMPORT { "import" }
| IN { "in" }
(* | INDUCTIVE { "inductive" } *)
| INVARIANT { "invariant" }
| LABEL { "label" }
(* | LEMMA { "lemma" } *)
(* | LET { "let" } *)
| MATCH { "match" }
(* | META { "meta" } *)
(* | MODULE { "module" } *)
| MUTABLE { "mutable" }
| NOT { "not" }
| OLD { "old" }
| PARTIAL { "partial" }
(* | PREDICATE { "predicate" } *)
| PRIVATE { "private" }
| PURE { "pure" }
| RAISE { "raise" }
| RAISES { "raises" }
| READS { "reads" }
| REC { "rec" }
| REQUIRES { "requires" }
| RETURNS { "returns" }
| SCOPE { "scope" }
| SO { "so" }
| THEN { "then" }
| THEORY { "theory" }
| TO { "to" }
| TRUE { "true" }
| TRY { "try" }
(* | TYPE { "type" } *)
(* | USE { "use" } *)
| VAL { "val" }
| VARIANT { "variant" }
| WHILE { "while" }
(* | WITH { "with" } *)
| WRITES { "writes" }
/* silent Menhir's errors about unreachable non terminal symbols */
dummy:
| module_head_parsing_only scope_head_parsing_only dummy_decl* EOF
{ }
dummy_decl:
| meta_decl {}
| use_clone_parsing_only {}
| prog_decl {}
| pure_decl {}
|