| 1 |
4 |
tbourke |
(* $Id: expressioncvt.sml 62 2008-08-20 11:20:33Z tbourke $
|
| 2 |
|
|
*
|
| 3 |
62 |
tbourke |
* Copyright (c) 2008 Timothy Bourke (University of NSW and NICTA)
|
| 4 |
|
|
* All rights reserved.
|
| 5 |
4 |
tbourke |
*
|
| 6 |
62 |
tbourke |
* This program is free software; you can redistribute it and/or modify it
|
| 7 |
|
|
* under the terms of the "BSD License" which is distributed with the
|
| 8 |
|
|
* software in the file LICENSE.
|
| 9 |
|
|
*
|
| 10 |
|
|
* This program is distributed in the hope that it will be useful, but
|
| 11 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the BSD
|
| 13 |
|
|
* License for more details.
|
| 14 |
4 |
tbourke |
*)
|
| 15 |
|
|
|
| 16 |
|
|
(* TODO:
|
| 17 |
|
|
* rename? now that it also includes some conversion functions for
|
| 18 |
|
|
declarations and environments.
|
| 19 |
|
|
*)
|
| 20 |
|
|
|
| 21 |
|
|
structure ExpressionCvt :> EXPRESSION_CVT
|
| 22 |
|
|
=
|
| 23 |
|
|
struct
|
| 24 |
|
|
structure E = Expression
|
| 25 |
|
|
structure D = Declaration
|
| 26 |
|
|
|
| 27 |
|
|
structure StringPPS = PPStreamFn (structure Token = StringToken
|
| 28 |
|
|
and Device = PPDevString)
|
| 29 |
|
|
structure StringPPD = PPDescFn (StringPPS)
|
| 30 |
11 |
tbourke |
structure StringEPP = ExpressionPPFn (structure PPD=StringPPD and E=E)
|
| 31 |
4 |
tbourke |
|
| 32 |
|
|
structure OutPPS = PPStreamFn (structure Token = StringToken
|
| 33 |
|
|
and Device = SimpleTextIODev)
|
| 34 |
|
|
structure OutPPD = PPDescFn (OutPPS)
|
| 35 |
11 |
tbourke |
structure OutEPP = ExpressionPPFn (structure PPD=OutPPD and E=E)
|
| 36 |
|
|
structure OutDPP = DeclarationPPFn (structure PPD=OutPPD
|
| 37 |
|
|
and D=D and EPP=OutEPP)
|
| 38 |
4 |
tbourke |
|
| 39 |
|
|
type expr = E.expr
|
| 40 |
|
|
and ty = E.ty
|
| 41 |
|
|
and var = E.var
|
| 42 |
|
|
and decl = D.decl
|
| 43 |
|
|
|
| 44 |
|
|
type outstream = TextIO.StreamIO.outstream
|
| 45 |
|
|
|
| 46 |
|
|
val width = ref 76
|
| 47 |
|
|
|
| 48 |
|
|
fun ppdToString pp_desc = let
|
| 49 |
|
|
val dev = PPDevString.openDev {dst="", wid=(!width)}
|
| 50 |
|
|
val strm = StringPPD.PPS.openStream dev
|
| 51 |
|
|
in
|
| 52 |
|
|
StringEPP.print strm pp_desc;
|
| 53 |
|
|
StringPPD.PPS.closeStream strm;
|
| 54 |
|
|
PPDevString.toString dev
|
| 55 |
|
|
end
|
| 56 |
|
|
|
| 57 |
|
|
fun ppdToOutput (os, pp_desc) = let
|
| 58 |
|
|
val dev = SimpleTextIODev.openDev {dst=TextIO.mkOutstream os,
|
| 59 |
|
|
wid=Settings.maxLabelWidth()}
|
| 60 |
|
|
val strm = OutPPD.PPS.openStream dev
|
| 61 |
|
|
in
|
| 62 |
|
|
OutEPP.print strm pp_desc;
|
| 63 |
|
|
OutPPD.PPS.closeStream strm
|
| 64 |
|
|
end
|
| 65 |
|
|
|
| 66 |
|
|
structure Expr = struct
|
| 67 |
|
|
fun toString e = ppdToString (StringEPP.fromExpr e)
|
| 68 |
|
|
(*val fromString = UppaalParse.parseExpression "ExpressionCvt"*)
|
| 69 |
|
|
fun toStream (os, e) = ppdToOutput (os, OutEPP.fromExpr e)
|
| 70 |
|
|
end
|
| 71 |
|
|
|
| 72 |
|
|
structure Ty = struct
|
| 73 |
|
|
fun toString t = ppdToString (StringEPP.fromType t)
|
| 74 |
|
|
fun toStream (os, t) = ppdToOutput (os, OutEPP.fromType t)
|
| 75 |
|
|
end
|
| 76 |
|
|
|
| 77 |
|
|
structure Var = struct
|
| 78 |
|
|
fun toString v = ppdToString (StringEPP.fromVar v)
|
| 79 |
|
|
fun toStream (os, v) = ppdToOutput (os, OutEPP.fromVar v)
|
| 80 |
|
|
end
|
| 81 |
|
|
|
| 82 |
|
|
structure Decl = struct
|
| 83 |
|
|
fun toStream (os, d) = ppdToOutput (os, OutDPP.fromDecl d)
|
| 84 |
|
|
end
|
| 85 |
|
|
|
| 86 |
|
|
fun selectToStream (os, sels) = ppdToOutput (os, OutEPP.fromSelects sels)
|
| 87 |
|
|
fun selectToString sels = ppdToString (StringEPP.fromSelects sels)
|
| 88 |
|
|
fun syncToStream (os, sync) = ppdToOutput (os, OutEPP.fromSync sync)
|
| 89 |
|
|
fun syncToString sync = ppdToString (StringEPP.fromSync sync)
|
| 90 |
|
|
fun exprlistToStream (os, exprs) = ppdToOutput (os,OutEPP.fromExprList exprs)
|
| 91 |
|
|
fun exprlistToString exprs = ppdToString (StringEPP.fromExprList exprs)
|
| 92 |
|
|
fun paramlistToStream (os, params) = ppdToOutput(os,OutDPP.fromParams params)
|
| 93 |
|
|
|
| 94 |
|
|
end
|
| 95 |
|
|
|