| author | kleing | 
| Wed, 19 Jun 2002 12:39:41 +0200 | |
| changeset 13224 | 6f0928a942d1 | 
| parent 13022 | b115b305612f | 
| child 15425 | 6356d2523f73 | 
| permissions | -rw-r--r-- | 
| 13020 | 1  | 
|
| 
13022
 
b115b305612f
New order in the loading of theories (Quote-antiquote right before the OG_Syntax and RG_Syntax respectively)
 
prensani 
parents: 
13020 
diff
changeset
 | 
2  | 
theory OG_Syntax = OG_Tactics + Quote_Antiquote:  | 
| 13020 | 3  | 
|
4  | 
text{* Syntax for commands and for assertions and boolean expressions in 
 | 
|
5  | 
 commands @{text com} and annotated commands @{text ann_com}. *}
 | 
|
6  | 
||
7  | 
syntax  | 
|
8  | 
  "_Assign"      :: "idt \<Rightarrow> 'b \<Rightarrow> 'a com"    ("(\<acute>_ :=/ _)" [70, 65] 61)
 | 
|
9  | 
  "_AnnAssign"   :: "'a assn \<Rightarrow> idt \<Rightarrow> 'b \<Rightarrow> 'a com"    ("(_ \<acute>_ :=/ _)" [90,70,65] 61)
 | 
|
10  | 
||
11  | 
translations  | 
|
12  | 
"\<acute>\<spacespace>x := a" \<rightharpoonup> "Basic \<guillemotleft>\<acute>\<spacespace>(_update_name x a)\<guillemotright>"  | 
|
13  | 
"r \<acute>\<spacespace>x := a" \<rightharpoonup> "AnnBasic r \<guillemotleft>\<acute>\<spacespace>(_update_name x a)\<guillemotright>"  | 
|
14  | 
||
15  | 
syntax  | 
|
16  | 
  "_AnnSkip"     :: "'a assn \<Rightarrow> 'a ann_com"              ("_//SKIP" [90] 63)
 | 
|
17  | 
  "_AnnSeq"      :: "'a ann_com \<Rightarrow> 'a ann_com \<Rightarrow> 'a ann_com"  ("_;;/ _" [60,61] 60)
 | 
|
18  | 
||
19  | 
"_AnnCond1" :: "'a assn \<Rightarrow> 'a bexp \<Rightarrow> 'a ann_com \<Rightarrow> 'a ann_com \<Rightarrow> 'a ann_com"  | 
|
20  | 
                    ("_ //IF _ /THEN _ /ELSE _ /FI"  [90,0,0,0] 61)
 | 
|
21  | 
"_AnnCond2" :: "'a assn \<Rightarrow> 'a bexp \<Rightarrow> 'a ann_com \<Rightarrow> 'a ann_com"  | 
|
22  | 
                    ("_ //IF _ /THEN _ /FI"  [90,0,0] 61)
 | 
|
23  | 
"_AnnWhile" :: "'a assn \<Rightarrow> 'a bexp \<Rightarrow> 'a assn \<Rightarrow> 'a ann_com \<Rightarrow> 'a ann_com"  | 
|
24  | 
                    ("_ //WHILE _ /INV _ //DO _//OD"  [90,0,0,0] 61)
 | 
|
25  | 
"_AnnAwait" :: "'a assn \<Rightarrow> 'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a ann_com"  | 
|
26  | 
                    ("_ //AWAIT _ /THEN /_ /END"  [90,0,0] 61)
 | 
|
27  | 
  "_AnnAtom"     :: "'a assn  \<Rightarrow> 'a com \<Rightarrow> 'a ann_com"   ("_//\<langle>_\<rangle>" [90,0] 61)
 | 
|
28  | 
  "_AnnWait"     :: "'a assn \<Rightarrow> 'a bexp \<Rightarrow> 'a ann_com"   ("_//WAIT _ END" [90,0] 61)
 | 
|
29  | 
||
30  | 
  "_Skip"        :: "'a com"                 ("SKIP" 63)
 | 
|
31  | 
  "_Seq"         :: "'a com \<Rightarrow> 'a com \<Rightarrow> 'a com" ("_,,/ _" [55, 56] 55)
 | 
|
32  | 
"_Cond" :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com \<Rightarrow> 'a com"  | 
|
33  | 
                                  ("(0IF _/ THEN _/ ELSE _/ FI)" [0, 0, 0] 61)
 | 
|
34  | 
  "_Cond2"       :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"   ("IF _ THEN _ FI" [0,0] 56)
 | 
|
35  | 
"_While_inv" :: "'a bexp \<Rightarrow> 'a assn \<Rightarrow> 'a com \<Rightarrow> 'a com"  | 
|
36  | 
                    ("(0WHILE _/ INV _ //DO _ /OD)"  [0, 0, 0] 61)
 | 
|
37  | 
"_While" :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com"  | 
|
38  | 
                    ("(0WHILE _ //DO _ /OD)"  [0, 0] 61)
 | 
|
39  | 
||
40  | 
translations  | 
|
41  | 
"SKIP" \<rightleftharpoons> "Basic id"  | 
|
42  | 
"c_1,, c_2" \<rightleftharpoons> "Seq c_1 c_2"  | 
|
43  | 
||
44  | 
  "IF b THEN c1 ELSE c2 FI" \<rightharpoonup> "Cond .{b}. c1 c2"
 | 
|
45  | 
"IF b THEN c FI" \<rightleftharpoons> "IF b THEN c ELSE SKIP FI"  | 
|
46  | 
  "WHILE b INV i DO c OD" \<rightharpoonup> "While .{b}. i c"
 | 
|
47  | 
"WHILE b DO c OD" \<rightleftharpoons> "WHILE b INV arbitrary DO c OD"  | 
|
48  | 
||
49  | 
"r SKIP" \<rightleftharpoons> "AnnBasic r id"  | 
|
50  | 
"c_1;; c_2" \<rightleftharpoons> "AnnSeq c_1 c_2"  | 
|
51  | 
  "r IF b THEN c1 ELSE c2 FI" \<rightharpoonup> "AnnCond1 r .{b}. c1 c2"
 | 
|
52  | 
  "r IF b THEN c FI" \<rightharpoonup> "AnnCond2 r .{b}. c"
 | 
|
53  | 
  "r WHILE b INV i DO c OD" \<rightharpoonup> "AnnWhile r .{b}. i c"
 | 
|
54  | 
  "r AWAIT b THEN c END" \<rightharpoonup> "AnnAwait r .{b}. c"
 | 
|
55  | 
"r \<langle>c\<rangle>" \<rightleftharpoons> "r AWAIT True THEN c END"  | 
|
56  | 
"r WAIT b END" \<rightleftharpoons> "r AWAIT b THEN SKIP END"  | 
|
57  | 
||
58  | 
nonterminals  | 
|
59  | 
prgs  | 
|
60  | 
||
61  | 
syntax  | 
|
62  | 
  "_PAR" :: "prgs \<Rightarrow> 'a"              ("COBEGIN//_//COEND" [57] 56)
 | 
|
63  | 
  "_prg" :: "['a, 'a] \<Rightarrow> prgs"        ("_//_" [60, 90] 57)
 | 
|
64  | 
  "_prgs" :: "['a, 'a, prgs] \<Rightarrow> prgs"  ("_//_//\<parallel>//_" [60,90,57] 57)
 | 
|
65  | 
||
66  | 
"_prg_scheme" :: "['a, 'a, 'a, 'a, 'a] \<Rightarrow> prgs"  | 
|
67  | 
                  ("SCHEME [_ \<le> _ < _] _// _" [0,0,0,60, 90] 57)
 | 
|
68  | 
||
69  | 
translations  | 
|
70  | 
"_prg c q" \<rightleftharpoons> "[(Some c, q)]"  | 
|
71  | 
"_prgs c q ps" \<rightleftharpoons> "(Some c, q) # ps"  | 
|
72  | 
"_PAR ps" \<rightleftharpoons> "Parallel ps"  | 
|
73  | 
||
74  | 
"_prg_scheme j i k c q" \<rightleftharpoons> "(map (\<lambda>i. (Some c, q)) [j..k(])"  | 
|
75  | 
||
76  | 
print_translation {*
 | 
|
77  | 
let  | 
|
78  | 
fun quote_tr' f (t :: ts) =  | 
|
79  | 
Term.list_comb (f $ Syntax.quote_tr' "_antiquote" t, ts)  | 
|
80  | 
| quote_tr' _ _ = raise Match;  | 
|
81  | 
||
82  | 
fun annquote_tr' f (r :: t :: ts) =  | 
|
83  | 
Term.list_comb (f $ r $ Syntax.quote_tr' "_antiquote" t, ts)  | 
|
84  | 
| annquote_tr' _ _ = raise Match;  | 
|
85  | 
||
86  | 
val assert_tr' = quote_tr' (Syntax.const "_Assert");  | 
|
87  | 
||
88  | 
    fun bexp_tr' name ((Const ("Collect", _) $ t) :: ts) =
 | 
|
89  | 
quote_tr' (Syntax.const name) (t :: ts)  | 
|
90  | 
| bexp_tr' _ _ = raise Match;  | 
|
91  | 
||
92  | 
    fun annbexp_tr' name (r :: (Const ("Collect", _) $ t) :: ts) =
 | 
|
93  | 
annquote_tr' (Syntax.const name) (r :: t :: ts)  | 
|
94  | 
| annbexp_tr' _ _ = raise Match;  | 
|
95  | 
||
96  | 
fun upd_tr' (x_upd, T) =  | 
|
97  | 
(case try (unsuffix RecordPackage.updateN) x_upd of  | 
|
98  | 
Some x => (x, if T = dummyT then T else Term.domain_type T)  | 
|
99  | 
| None => raise Match);  | 
|
100  | 
||
101  | 
fun update_name_tr' (Free x) = Free (upd_tr' x)  | 
|
102  | 
      | update_name_tr' ((c as Const ("_free", _)) $ Free x) =
 | 
|
103  | 
c $ Free (upd_tr' x)  | 
|
104  | 
| update_name_tr' (Const x) = Const (upd_tr' x)  | 
|
105  | 
| update_name_tr' _ = raise Match;  | 
|
106  | 
||
107  | 
fun assign_tr' (Abs (x, _, f $ t $ Bound 0) :: ts) =  | 
|
108  | 
quote_tr' (Syntax.const "_Assign" $ update_name_tr' f)  | 
|
109  | 
(Abs (x, dummyT, t) :: ts)  | 
|
110  | 
| assign_tr' _ = raise Match;  | 
|
111  | 
||
112  | 
fun annassign_tr' (r :: Abs (x, _, f $ t $ Bound 0) :: ts) =  | 
|
113  | 
quote_tr' (Syntax.const "_AnnAssign" $ r $ update_name_tr' f)  | 
|
114  | 
(Abs (x, dummyT, t) :: ts)  | 
|
115  | 
| annassign_tr' _ = raise Match;  | 
|
116  | 
||
117  | 
    fun Parallel_PAR [(Const ("Cons",_) $ (Const ("Pair",_) $ (Const ("Some",_) $ t1 ) $ t2) $ Const ("Nil",_))] = 
 | 
|
118  | 
(Syntax.const "_prg" $ t1 $ t2)  | 
|
119  | 
      | Parallel_PAR [(Const ("Cons",_) $ (Const ("Pair",_) $ (Const ("Some",_) $ t1) $ t2) $ ts)] =
 | 
|
120  | 
(Syntax.const "_prgs" $ t1 $ t2 $ Parallel_PAR [ts])  | 
|
121  | 
| Parallel_PAR _ = raise Match;  | 
|
122  | 
||
123  | 
fun Parallel_tr' ts = Syntax.const "_PAR" $ Parallel_PAR ts;  | 
|
124  | 
in  | 
|
125  | 
    [("Collect", assert_tr'), ("Basic", assign_tr'), 
 | 
|
126  | 
      ("Cond", bexp_tr' "_Cond"), ("While", bexp_tr' "_While_inv"),
 | 
|
127  | 
      ("AnnBasic", annassign_tr'), 
 | 
|
128  | 
      ("AnnWhile", annbexp_tr' "_AnnWhile"), ("AnnAwait", annbexp_tr' "_AnnAwait"),
 | 
|
129  | 
      ("AnnCond1", annbexp_tr' "_AnnCond1"), ("AnnCond2", annbexp_tr' "_AnnCond2")]
 | 
|
130  | 
||
131  | 
end  | 
|
132  | 
||
133  | 
*}  | 
|
134  | 
||
135  | 
end  |