src/HOL/Hoare_Parallel/RG_Syntax.thy
author wenzelm
Thu May 24 17:25:53 2012 +0200 (2012-05-24)
changeset 47988 e4b69e10b990
parent 42284 326f57825e1a
child 52143 36ffe23b25f8
permissions -rw-r--r--
tuned proofs;
     1 header {* \section{Concrete Syntax} *}
     2 
     3 theory RG_Syntax
     4 imports RG_Hoare Quote_Antiquote
     5 begin
     6 
     7 abbreviation Skip :: "'a com"  ("SKIP")
     8   where "SKIP \<equiv> Basic id"
     9 
    10 notation Seq  ("(_;;/ _)" [60,61] 60)
    11 
    12 syntax
    13   "_Assign"    :: "idt \<Rightarrow> 'b \<Rightarrow> 'a com"                     ("(\<acute>_ :=/ _)" [70, 65] 61)
    14   "_Cond"      :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com \<Rightarrow> 'a com"   ("(0IF _/ THEN _/ ELSE _/FI)" [0, 0, 0] 61)
    15   "_Cond2"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0IF _ THEN _ FI)" [0,0] 56)
    16   "_While"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0WHILE _ /DO _ /OD)"  [0, 0] 61)
    17   "_Await"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0AWAIT _ /THEN /_ /END)"  [0,0] 61)
    18   "_Atom"      :: "'a com \<Rightarrow> 'a com"                        ("(\<langle>_\<rangle>)" 61)
    19   "_Wait"      :: "'a bexp \<Rightarrow> 'a com"                       ("(0WAIT _ END)" 61)
    20 
    21 translations
    22   "\<acute>x := a" \<rightharpoonup> "CONST Basic \<guillemotleft>\<acute>(_update_name x (\<lambda>_. a))\<guillemotright>"
    23   "IF b THEN c1 ELSE c2 FI" \<rightharpoonup> "CONST Cond .{b}. c1 c2"
    24   "IF b THEN c FI" \<rightleftharpoons> "IF b THEN c ELSE SKIP FI"
    25   "WHILE b DO c OD" \<rightharpoonup> "CONST While .{b}. c"
    26   "AWAIT b THEN c END" \<rightleftharpoons> "CONST Await .{b}. c"
    27   "\<langle>c\<rangle>" \<rightleftharpoons> "AWAIT CONST True THEN c END"
    28   "WAIT b END" \<rightleftharpoons> "AWAIT b THEN SKIP END"
    29 
    30 nonterminal prgs
    31 
    32 syntax
    33   "_PAR"        :: "prgs \<Rightarrow> 'a"              ("COBEGIN//_//COEND" 60)
    34   "_prg"        :: "'a \<Rightarrow> prgs"              ("_" 57)
    35   "_prgs"       :: "['a, prgs] \<Rightarrow> prgs"      ("_//\<parallel>//_" [60,57] 57)
    36 
    37 translations
    38   "_prg a" \<rightharpoonup> "[a]"
    39   "_prgs a ps" \<rightharpoonup> "a # ps"
    40   "_PAR ps" \<rightharpoonup> "ps"
    41 
    42 syntax
    43   "_prg_scheme" :: "['a, 'a, 'a, 'a] \<Rightarrow> prgs"  ("SCHEME [_ \<le> _ < _] _" [0,0,0,60] 57)
    44 
    45 translations
    46   "_prg_scheme j i k c" \<rightleftharpoons> "(CONST map (\<lambda>i. c) [j..<k])"
    47 
    48 text {* Translations for variables before and after a transition: *}
    49 
    50 syntax 
    51   "_before" :: "id \<Rightarrow> 'a" ("\<ordmasculine>_")
    52   "_after"  :: "id \<Rightarrow> 'a" ("\<ordfeminine>_")
    53  
    54 translations
    55   "\<ordmasculine>x" \<rightleftharpoons> "x \<acute>CONST fst"
    56   "\<ordfeminine>x" \<rightleftharpoons> "x \<acute>CONST snd"
    57 
    58 print_translation {*
    59   let
    60     fun quote_tr' f (t :: ts) =
    61           Term.list_comb (f $ Syntax_Trans.quote_tr' @{syntax_const "_antiquote"} t, ts)
    62       | quote_tr' _ _ = raise Match;
    63 
    64     val assert_tr' = quote_tr' (Syntax.const @{syntax_const "_Assert"});
    65 
    66     fun bexp_tr' name ((Const (@{const_syntax Collect}, _) $ t) :: ts) =
    67           quote_tr' (Syntax.const name) (t :: ts)
    68       | bexp_tr' _ _ = raise Match;
    69 
    70     fun assign_tr' (Abs (x, _, f $ k $ Bound 0) :: ts) =
    71           quote_tr' (Syntax.const @{syntax_const "_Assign"} $ Syntax_Trans.update_name_tr' f)
    72             (Abs (x, dummyT, Syntax_Trans.const_abs_tr' k) :: ts)
    73       | assign_tr' _ = raise Match;
    74   in
    75    [(@{const_syntax Collect}, assert_tr'),
    76     (@{const_syntax Basic}, assign_tr'),
    77     (@{const_syntax Cond}, bexp_tr' @{syntax_const "_Cond"}),
    78     (@{const_syntax While}, bexp_tr' @{syntax_const "_While"})]
    79   end
    80 *}
    81 
    82 end