src/Tools/isac/ProgLang/Tactical.thy
author wneuper <Walther.Neuper@jku.at>
Mon, 30 Jan 2023 12:11:40 +0100
changeset 60661 91c30b11e5bc
parent 60658 1c089105f581
permissions -rw-r--r--
cleanup parse #4: eliminate TermC.parse
     1 (* Title:  tacticals for programs
     2    Author: Walther Neuper, Aug.2019
     3    (c) due to copyright terms
     4  *)
     5 theory Tactical
     6   imports "$ISABELLE_ISAC/BaseDefinitions/BaseDefinitions"
     7 begin
     8 
     9 text \<open>Abstract:
    10   Define specific constants for tacticals, which determine the flow of evaluation in programs.
    11   Tacticals are not visible in calculations, which are generated by programs as a side effect.
    12 \<close>
    13 subsection \<open>Consts for tacticals\<close>
    14 consts
    15   Chain    :: "['a => 'a, 'a => 'a, 'a] => 'a" (infixr "#>" 10)
    16   Try      :: "['a => 'a, 'a] => 'a"
    17   Repeat   :: "['a => 'a, 'a] => 'a" 
    18   Or       :: "['a => 'a, 'a => 'a, 'a] => 'a" (infixr "Or" 10)
    19   While    :: "[bool, 'a => 'a, 'a] => 'a" ("((While (_) Do)//(_))" 9)
    20   If       :: "[bool, 'a, 'a] => 'a"       ("(If (_)/ Then (_)/ Else (_))" 10)
    21 
    22 subsection \<open>ML code for tacticals\<close>
    23 ML \<open>
    24 signature TACTICAL =
    25 sig
    26   val is: term -> bool
    27   val contained_in: term -> bool
    28 end
    29 
    30 \<close> ML \<open>
    31 (**)
    32 structure Tactical(**): TACTICAL(**) =
    33 struct
    34 (**)
    35 
    36 val SOME (Let $ _ $ _) = ParseC.term_opt @{context} "let aaa = 1 in aaa"
    37 val SOME (Chain) = ParseC.term_opt @{context} "Chain";
    38 val SOME (Try) = ParseC.term_opt @{context} "Try";
    39 val SOME (Repeat) = ParseC.term_opt @{context} "Repeat";
    40 val SOME (Or $ _ $ _) = ParseC.term_opt @{context} "aaa Or bbb";
    41 val SOME (While $ _ $ _) = ParseC.term_opt @{context} "While aaa Do bbb";
    42 val SOME (If $ _ $ _ $ _) = ParseC.term_opt @{context} "If aaa Then bbb Else ccc";
    43 
    44 val all_Consts = [Let, Chain, Try, Repeat, Or, While, If]
    45 
    46 fun is t = TermC.contains_Const_typeless all_Consts t
    47 
    48 fun contained_in t =
    49   let
    50     fun eqal (Const (fid, _), Const (constid, _)) = fid = constid
    51       | eqal _ = false
    52     val (f, args) = strip_comb t
    53   in
    54     if member eqal all_Consts f
    55     then true
    56     else fold cor_ (map contained_in args) false
    57   end 
    58 
    59 (**)end(**)
    60 \<close> ML \<open>
    61 \<close>
    62 
    63 end
    64