src/HOL/Hoare_Parallel/RG_Syntax.thy
author wenzelm
Tue Feb 16 14:08:39 2010 +0100 (2010-02-16)
changeset 35145 f132a4fd8679
parent 35113 1a0c129bb2e0
child 41229 d797baa3d57c
permissions -rw-r--r--
moved generic update_name to Pure syntax -- not specific to HOL/record;
prensani@13099
     1
header {* \section{Concrete Syntax} *}
prensani@13020
     2
nipkow@15425
     3
theory RG_Syntax
nipkow@15425
     4
imports RG_Hoare Quote_Antiquote
nipkow@15425
     5
begin
prensani@13020
     6
wenzelm@35107
     7
abbreviation Skip :: "'a com"  ("SKIP")
wenzelm@35107
     8
  where "SKIP \<equiv> Basic id"
wenzelm@35107
     9
wenzelm@35107
    10
notation Seq  ("(_;;/ _)" [60,61] 60)
wenzelm@35107
    11
prensani@13020
    12
syntax
prensani@13020
    13
  "_Assign"    :: "idt \<Rightarrow> 'b \<Rightarrow> 'a com"                     ("(\<acute>_ :=/ _)" [70, 65] 61)
prensani@13020
    14
  "_Cond"      :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com \<Rightarrow> 'a com"   ("(0IF _/ THEN _/ ELSE _/FI)" [0, 0, 0] 61)
prensani@13020
    15
  "_Cond2"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0IF _ THEN _ FI)" [0,0] 56)
prensani@13020
    16
  "_While"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0WHILE _ /DO _ /OD)"  [0, 0] 61)
prensani@13020
    17
  "_Await"     :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"             ("(0AWAIT _ /THEN /_ /END)"  [0,0] 61)
prensani@13020
    18
  "_Atom"      :: "'a com \<Rightarrow> 'a com"                        ("(\<langle>_\<rangle>)" 61)
prensani@13020
    19
  "_Wait"      :: "'a bexp \<Rightarrow> 'a com"                       ("(0WAIT _ END)" 61)
prensani@13020
    20
prensani@13020
    21
translations
wenzelm@35107
    22
  "\<acute>x := a" \<rightharpoonup> "CONST Basic \<guillemotleft>\<acute>(_update_name x (\<lambda>_. a))\<guillemotright>"
wenzelm@35113
    23
  "IF b THEN c1 ELSE c2 FI" \<rightharpoonup> "CONST Cond .{b}. c1 c2"
prensani@13020
    24
  "IF b THEN c FI" \<rightleftharpoons> "IF b THEN c ELSE SKIP FI"
wenzelm@35113
    25
  "WHILE b DO c OD" \<rightharpoonup> "CONST While .{b}. c"
wenzelm@35113
    26
  "AWAIT b THEN c END" \<rightleftharpoons> "CONST Await .{b}. c"
wenzelm@35113
    27
  "\<langle>c\<rangle>" \<rightleftharpoons> "AWAIT CONST True THEN c END"
prensani@13020
    28
  "WAIT b END" \<rightleftharpoons> "AWAIT b THEN SKIP END"
prensani@13020
    29
prensani@13020
    30
nonterminals
prensani@13020
    31
  prgs
prensani@13020
    32
prensani@13020
    33
syntax
prensani@13020
    34
  "_PAR"        :: "prgs \<Rightarrow> 'a"              ("COBEGIN//_//COEND" 60)
prensani@13020
    35
  "_prg"        :: "'a \<Rightarrow> prgs"              ("_" 57)
prensani@13020
    36
  "_prgs"       :: "['a, prgs] \<Rightarrow> prgs"      ("_//\<parallel>//_" [60,57] 57)
prensani@13020
    37
prensani@13020
    38
translations
prensani@13020
    39
  "_prg a" \<rightharpoonup> "[a]"
prensani@13020
    40
  "_prgs a ps" \<rightharpoonup> "a # ps"
prensani@13020
    41
  "_PAR ps" \<rightharpoonup> "ps"
prensani@13020
    42
prensani@13020
    43
syntax
prensani@13020
    44
  "_prg_scheme" :: "['a, 'a, 'a, 'a] \<Rightarrow> prgs"  ("SCHEME [_ \<le> _ < _] _" [0,0,0,60] 57)
prensani@13020
    45
prensani@13020
    46
translations
haftmann@34940
    47
  "_prg_scheme j i k c" \<rightleftharpoons> "(CONST map (\<lambda>i. c) [j..<k])"
prensani@13020
    48
prensani@13020
    49
text {* Translations for variables before and after a transition: *}
prensani@13020
    50
prensani@13020
    51
syntax 
prensani@13020
    52
  "_before" :: "id \<Rightarrow> 'a" ("\<ordmasculine>_")
prensani@13020
    53
  "_after"  :: "id \<Rightarrow> 'a" ("\<ordfeminine>_")
prensani@13020
    54
 
prensani@13020
    55
translations
wenzelm@35107
    56
  "\<ordmasculine>x" \<rightleftharpoons> "x \<acute>CONST fst"
wenzelm@35107
    57
  "\<ordfeminine>x" \<rightleftharpoons> "x \<acute>CONST snd"
prensani@13020
    58
prensani@13020
    59
print_translation {*
prensani@13020
    60
  let
prensani@13020
    61
    fun quote_tr' f (t :: ts) =
wenzelm@35113
    62
          Term.list_comb (f $ Syntax.quote_tr' @{syntax_const "_antiquote"} t, ts)
prensani@13020
    63
      | quote_tr' _ _ = raise Match;
prensani@13020
    64
wenzelm@35113
    65
    val assert_tr' = quote_tr' (Syntax.const @{syntax_const "_Assert"});
prensani@13020
    66
wenzelm@35107
    67
    fun bexp_tr' name ((Const (@{const_syntax Collect}, _) $ t) :: ts) =
prensani@13020
    68
          quote_tr' (Syntax.const name) (t :: ts)
prensani@13020
    69
      | bexp_tr' _ _ = raise Match;
prensani@13020
    70
wenzelm@35107
    71
    fun K_tr' (Abs (_, _, t)) =
wenzelm@35107
    72
          if null (loose_bnos t) then t else raise Match
wenzelm@35107
    73
      | K_tr' (Abs (_, _, Abs (_, _, t) $ Bound 0)) =
wenzelm@35107
    74
          if null (loose_bnos t) then t else raise Match
schirmer@25706
    75
      | K_tr' _ = raise Match;
schirmer@25706
    76
schirmer@25706
    77
    fun assign_tr' (Abs (x, _, f $ k $ Bound 0) :: ts) =
wenzelm@35145
    78
          quote_tr' (Syntax.const @{syntax_const "_Assign"} $ Syntax.update_name_tr' f)
schirmer@25706
    79
            (Abs (x, dummyT, K_tr' k) :: ts)
prensani@13020
    80
      | assign_tr' _ = raise Match;
prensani@13020
    81
  in
wenzelm@35107
    82
   [(@{const_syntax Collect}, assert_tr'),
wenzelm@35107
    83
    (@{const_syntax Basic}, assign_tr'),
wenzelm@35113
    84
    (@{const_syntax Cond}, bexp_tr' @{syntax_const "_Cond"}),
wenzelm@35113
    85
    (@{const_syntax While}, bexp_tr' @{syntax_const "_While"})]
prensani@13020
    86
  end
prensani@13020
    87
*}
prensani@13020
    88
prensani@13020
    89
end