: mira2lml - Convert Miranda to LML #Miranda is a trademark of Research Software Limited #Version 0.00 04-Jul-1991 Denis Howe #Please send me a copy of any modifications you make. #Can't handle many things including multi-line guards. exec < $1 [ $2 ] && exec > $2 sed " 1i\\ -- $1 converted to LML by $USER on `date`\\ \\ let rec\\ foldl f r [] = r\\ || foldl f r (x.xs) = foldl f (f x r) xs\\ \\ and foldr f r [] = r\\ || foldr f r (x.xs) = f x (foldr f r xs)\\ \\ #Comment to end of line - no further substitutions /||/ {s/||/--/;b } #Comment out type declarations /.*::/{s/^/--/;b } #Infix cons s/:/./g #List append operator s/++/@/g #List length function s/#/ length /g #Dollar converts function to infix operator s/\\$//g #as is a reserved word in LML - prepend a _ s/\([^A-Za-z_']\)as/\1_as/g s/^as/_as/ #o is an operator - prepend a _ s/\([^A-Za-z_']\)o\([^A-Za-z_']\)/\1_o\2/g s/^o\([^A-Za-z_']\)/_o\1/g #Replace commas within []s with ;s (unless within ()s) and []s to _{_ _}_s #Loop until no more substs : lcommas s/[[;]\([^],(]*\),\([^]]*\)]/\[\1;\2]/g s/\[\([^],]*\)\]/_{_\1_}_/g t lcommas #Restore [] s/_{_/[/g s/_}_/]/g #Temporarily replace commas within ()s to #s and ()s to _{_ _}_s #Loop until no more substs : commas s/[(#]\([^,)]*\),\([^)]*\))/_{_\1#\2_}_/g s/(\([^),]*\))/_{_\1_}_/g t commas #Restore () s/_{_/(/g s/_}_/)/g #Commas in comments : comcom s/\(--.*\),/\1#/g t comcom #The only commas left now introduce guards, change them to _iff_ s/,/_iff_/g #Restore other commas s/#/,/g #Replace = _iff_ with & = s/=\(.*\)_iff_\(.*\)/\& (\2) =\1/g #| is 'such that' in ZF expression (do after list separator) s/|/;;/g #Infix boolean or (do after 'such that') s?\\\/?|?g #Prepend 'and' to lines containing '=' s/[^-].*=/and &/ " | awk '$1 == "and" { if ($2 == func) { printf "|| "; for (i = 2; i<=NF; i++) printf ($i " "); printf "\n"; next; } else if ($2 == "where") { for (i = 2; i<=NF; i++) printf ($i " "); printf "\n"; next; } else func = $2; } { print } '