% $Id: Conversions.oz,v 1.1 2009/08/28 19:19:54 leavens Exp leavens $ % Conversions between expressions and pattern ASTs % AUTHOR: Gary T. Leavens declare fun {Pattern2Exp Pat} %% ENSURES: Result is an expression AST that represents the pattern Pat case Pat of varIdPat(V) then varIdExp(V) [] atomPat(A) then atomExp(A) [] boolPat(B) then boolExp(B) [] recordPat(A FL) then recordExp(atomExp(A) FL) end end fun {Exp2Pattern Expr} %% ENSURES: Result is an pattern AST that represents the expression Exp case Expr of varIdExp(V POS) then varIdPat(V POS) [] varIdExp(V ...) then varIdPat(V) [] atomExp(A POS) then atomPat(A POS) [] atomExp(A ...) then atomPat(A) [] boolExp(B POS) then boolPat(B POS) [] boolExp(B ...) then boolPat(B) [] recordExp(atomExp(A) FL POS) then recordPat(A FL POS) [] recordExp(atomExp(A) FL ...) then recordPat(A FL) else {Exception.raiseError wrongExpressionForPattern(Expr)} raise Expr end end end