src/HOL/Hoare_Parallel/RG_Syntax.thy
author wenzelm
Sat Mar 26 12:01:40 2011 +0100 (2011-03-26)
changeset 42086 74bf78db0d87
parent 41229 d797baa3d57c
child 42284 326f57825e1a
permissions -rw-r--r--
added Syntax.const_abs_tr' with proper eta_abs and Term.is_dependent;
recovered printing of Hoare assign statements from 45d090186bbe;
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
wenzelm@41229
    30
nonterminal prgs
prensani@13020
    31
prensani@13020
    32
syntax
prensani@13020
    33
  "_PAR"        :: "prgs \<Rightarrow> 'a"              ("COBEGIN//_//COEND" 60)
prensani@13020
    34
  "_prg"        :: "'a \<Rightarrow> prgs"              ("_" 57)
prensani@13020
    35
  "_prgs"       :: "['a, prgs] \<Rightarrow> prgs"      ("_//\<parallel>//_" [60,57] 57)
prensani@13020
    36
prensani@13020
    37
translations
prensani@13020
    38
  "_prg a" \<rightharpoonup> "[a]"
prensani@13020
    39
  "_prgs a ps" \<rightharpoonup> "a # ps"
prensani@13020
    40
  "_PAR ps" \<rightharpoonup> "ps"
prensani@13020
    41
prensani@13020
    42
syntax
prensani@13020
    43
  "_prg_scheme" :: "['a, 'a, 'a, 'a] \<Rightarrow> prgs"  ("SCHEME [_ \<le> _ < _] _" [0,0,0,60] 57)
prensani@13020
    44
prensani@13020
    45
translations
haftmann@34940
    46
  "_prg_scheme j i k c" \<rightleftharpoons> "(CONST map (\<lambda>i. c) [j..<k])"
prensani@13020
    47
prensani@13020
    48
text {* Translations for variables before and after a transition: *}
prensani@13020
    49
prensani@13020
    50
syntax 
prensani@13020
    51
  "_before" :: "id \<Rightarrow> 'a" ("\<ordmasculine>_")
prensani@13020
    52
  "_after"  :: "id \<Rightarrow> 'a" ("\<ordfeminine>_")
prensani@13020
    53
 
prensani@13020
    54
translations
wenzelm@35107
    55
  "\<ordmasculine>x" \<rightleftharpoons> "x \<acute>CONST fst"
wenzelm@35107
    56
  "\<ordfeminine>x" \<rightleftharpoons> "x \<acute>CONST snd"
prensani@13020
    57
prensani@13020
    58
print_translation {*
prensani@13020
    59
  let
prensani@13020
    60
    fun quote_tr' f (t :: ts) =
wenzelm@35113
    61
          Term.list_comb (f $ Syntax.quote_tr' @{syntax_const "_antiquote"} t, ts)
prensani@13020
    62
      | quote_tr' _ _ = raise Match;
prensani@13020
    63
wenzelm@35113
    64
    val assert_tr' = quote_tr' (Syntax.const @{syntax_const "_Assert"});
prensani@13020
    65
wenzelm@35107
    66
    fun bexp_tr' name ((Const (@{const_syntax Collect}, _) $ t) :: ts) =
prensani@13020
    67
          quote_tr' (Syntax.const name) (t :: ts)
prensani@13020
    68
      | bexp_tr' _ _ = raise Match;
prensani@13020
    69
schirmer@25706
    70
    fun assign_tr' (Abs (x, _, f $ k $ Bound 0) :: ts) =
wenzelm@35145
    71
          quote_tr' (Syntax.const @{syntax_const "_Assign"} $ Syntax.update_name_tr' f)
wenzelm@42086
    72
            (Abs (x, dummyT, Syntax.const_abs_tr' k) :: ts)
prensani@13020
    73
      | assign_tr' _ = raise Match;
prensani@13020
    74
  in
wenzelm@35107
    75
   [(@{const_syntax Collect}, assert_tr'),
wenzelm@35107
    76
    (@{const_syntax Basic}, assign_tr'),
wenzelm@35113
    77
    (@{const_syntax Cond}, bexp_tr' @{syntax_const "_Cond"}),
wenzelm@35113
    78
    (@{const_syntax While}, bexp_tr' @{syntax_const "_While"})]
prensani@13020
    79
  end
prensani@13020
    80
*}
prensani@13020
    81
prensani@13020
    82
end