1 -- finite automata on trees (arbitrary term algebras) 2 3 module FA 4 5 ( Auto 6 7 -- export something 8 9 , e2d 10 , t2d 11 12 , d2t 13 , d2e 14 15 16 , fids -- identifiers 17 , hsTNFA -- possible default operations 18 19 -- above this line, eveyrthing is fine, abstract, and so on 20 -- below is some stuff that is exported 21 -- because the module structure isn't quite right 22 23 24 , TNFA(..) -- todo: make abstract 25 26 27 ) 28 29 where 30 31 import Set 32 import FiniteMap 33 34 import Options -- may modify behaviour 35 36 import Sorters 37 38 39 import TA -- term algebra 40 41 import Ids 42 import Syntax 43 44 import Stuff 45 46 import FAtypes 47 import FAconv 48 49 import FAuseful 50 import FAunify 51 52 import FAdet 53 import FAmin 54 55 import FAunion 56 import FAintersect 57 import FAcon 58 import FAminus 59 60 import FAtimes 61 import FAstar 62 import FArquotient 63 import FAlquotient 64 65 66 67 import ForwardS 68 import CForwardS 69 70 import BackwardS 71 import CBackwardS 72 73 import SaturnS 74 75 import Instance 76 77 -- import CloseS 78 79 ----------------------------------------------------------------------- 80 81 -- operations that are probably used often 82 83 e2d :: (Show a, Ord a) => Opts -> ETNFA a -> BDFA Int 84 e2d opts = tnfa2bdfa opts . etnfa2tnfa opts 85 86 87 88 t2d :: (Show a, Ord a) => Opts -> TNFA a -> BDFA Int 89 t2d opts = tnfa2bdfa opts 90 91 d2t :: (Show a, Ord a) => Opts -> BDFA a -> TNFA a 92 d2t opts = bnfa2tnfa opts . bdfa2bnfa opts 93 94 d2e :: (Show a, Ord a) => Opts -> BDFA a -> ETNFA a 95 d2e opts = tnfa2etnfa opts . bnfa2tnfa opts . bdfa2bnfa opts 96 97 ---------------------------------------------------------------------------- 98 99 100 101 fids :: [ (Id, Opts -> [TNFA Int] -> TNFA Int) ] 102 fids = 103 [ ( mkid "++" (Passive "++") (Just 2) Op Op (Just 30) Lft 104 , \ opts -> foldl1 (unionTNFA opts) ) 105 106 -- cannot use "--" because that's a comment 107 , ( mkid "\\\\" (Passive "\\\\") (Just 2) Op Op (Just 40) Lft 108 , \ opts -> foldr1 (minusTNFA opts) ) 109 110 , ( mkid "&" (Passive "&") (Just 2) Op Op (Just 50) Lft 111 , \opts -> foldl1 (intersectTNFA opts) ) 112 113 , ( mkid "->" (Passive "\\longrightarrow") (Just 2) Op Op (Just 20) Lft 114 , error "never evaluate fids.(->)" ) 115 116 , ( mkid ";" (Passive ";") (Just 2) Op Op (Just 10) Lft 117 -- todo: this is the wrong place 118 , error "never evaluate (;)" ) 119 , ( mkid "=" (Passive "=") (Just 2) Op Op (Just 15) Lft 120 -- todo: this is the wrong place 121 , error "never evaluate (=)" ) 122 123 , ( userfun 1 "det" 124 , \ opts [x] -> detTNFA opts x ) 125 , ( userfun 1 "min" 126 , \ opts [x] -> minTNFA opts x ) 127 , ( userfun 1 "useful" 128 , \ opts [x] -> usefulTNFA opts x ) 129 , ( userfun 1 "unify" 130 , \ opts [x] -> unifyTNFA opts x ) 131 132 , ( userfun 3 "times" 133 , \ opts xs -> timesTNFApublic opts xs ) 134 , ( userfun 3 "star" 135 , \ opts xs -> starTNFApublic opts xs ) 136 , ( userfun 3 "rquotient" 137 , \ opts xs -> rquotientTNFApublic opts xs ) 138 , ( userfun 3 "lquotient" 139 , \ opts xs -> lquotientTNFApublic opts xs ) 140 141 , ( userfun 1 "forwardS" 142 , \ opts xs -> forwardSpublic opts xs ) 143 , ( userfun 1 "cforwardS" 144 , \ opts xs -> cforwardSpublic opts xs ) 145 146 , ( userfun 1 "backwardS" 147 , \ opts xs -> backwardSpublic opts xs ) 148 , ( userfun 1 "cbackwardS" 149 , \ opts xs -> cbackwardSpublic opts xs ) 150 151 152 , ( userfun 1 "saturnS" 153 , \ opts xs -> saturnSpublic opts xs ) 154 155 , ( userfun 1 "inst" 156 , \ opts xs -> instpublic opts xs ) 157 158 159 -- broken 160 -- , ( userfun 1 "closeS" 161 -- , \ opts xs -> closeSpublic opts xs ) 162 163 ] 164 165 -- some transformations (that keep the meaning) 166 -- most imortant (costly) first 167 hsTNFA = ["min","det","useful","unify"] 168 169 170