diff options
-rw-r--r-- | src/ChangeLog | 8 | ||||
-rw-r--r-- | src/algebra/mkfunc.spad.pamphlet | 16 | ||||
-rw-r--r-- | src/interp/i-output.boot | 96 |
3 files changed, 116 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d014fe6f..4c85ff21 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2008-10-14 Gabriel Dos Reis <gdr@cs.tamu.edu> + * algebra/mkfunc.spad.pamphlet (coerce$InputForm): Display + InputForm as a one-dimensional stream of characters suitable + for input to the interpreter. + * interp/i-output.boot: Implement conversion of InputForm to + displayed OutputForm. + +2008-10-14 Gabriel Dos Reis <gdr@cs.tamu.edu> + * interp/i-spec2.boot (upQUOTE): Quoted forms belong to InputForm. * interp/sys-constants.boot ($InputForm): New. diff --git a/src/algebra/mkfunc.spad.pamphlet b/src/algebra/mkfunc.spad.pamphlet index a0edac2d..12194aff 100644 --- a/src/algebra/mkfunc.spad.pamphlet +++ b/src/algebra/mkfunc.spad.pamphlet @@ -1,21 +1,24 @@ \documentclass{article} \usepackage{axiom} -\begin{document} -\title{\$SPAD/src/algebra mkfunc.spad} + +\title{src/algebra mkfunc.spad} \author{Manuel Bronstein} + +\begin{document} \maketitle \begin{abstract} \end{abstract} -\eject \tableofcontents \eject + \section{domain INFORM InputForm} + <<domain INFORM InputForm>>= )abbrev domain INFORM InputForm ++ Parser forms ++ Author: Manuel Bronstein ++ Date Created: ??? -++ Date Last Updated: September 18, 2008 +++ Date Last Updated: October 14, 2008 ++ Description: ++ Domain of parsed forms which can be passed to the interpreter. ++ This is also the interface between algebra code and facilities @@ -191,6 +194,11 @@ InputForm(): s2 = 1 => s1 conv [convert("/"::Symbol), s1, s2]$List(%) + -- A displayed form of an InputForm should be suitable as + -- input to the interpreter parser. + coerce(x: %): OutputForm == + inputForm2OutputForm(x)$Lisp + @ \section{package INFORM1 InputFormFunctions1} <<package INFORM1 InputFormFunctions1>>= diff --git a/src/interp/i-output.boot b/src/interp/i-output.boot index c31616c1..f52dd4fd 100644 --- a/src/interp/i-output.boot +++ b/src/interp/i-output.boot @@ -2581,3 +2581,99 @@ maPrin u == form if ^$collectOutput then PRETTYPRINT(u,$algebraOutputStream) nil + + +--% Rendering of InputForm + +$allClassicOps == + ["~","#","-","**","^","*","/","rem","quo","+","-", + "@","::","$", "pretend"] + +isUnaryPrefix op == + op in '(_~ _# _-) + +primaryForm2String x == + x = nil => '"" + STRINGP x => x + x = $EmptyMode => specialChar 'quad + IDENTP x => SYMBOL_-NAME x + atom x => WRITE_-TO_-STRING x + strconc('"(",inputForm2String x, '")") + +callForm2String x == + atom x => primaryForm2String x + [op,:args] := x + + op in $allClassicOps => primaryForm2String x + + #args = 0 => + op = "Zero" => '"0" + op = "One" => '"1" + constructor? op => primaryForm2String op + strconc(inputForm2String op, '"()") + + "strconc"/[inputForm2String op, '"(",:args','")"] where + args' := [toString(a,i) for a in args for i in 0..] + toString(a,i) == + i = 0 => inputForm2String a + strconc('",",inputForm2String a) + +typedForm2String(s,x,t) == + s = "pretend" => + strconc(primaryForm2String x, '" pretend ", callForm2String t) + strconc(primaryForm2String x, SYMBOL_-NAME s, callForm2String t) + +expForm2String x == + x is [op,lhs,rhs] and op in '(** _^) => + strconc(expForm2String lhs,'"^", primaryForm2String rhs) + callForm2String x + +unaryForm2String x == + x is [op,arg] and isUnaryPrefix op => + strconc(inputForm2String op, inputForm2String arg) + expForm2String x + +multForm2String x == + x isnt ["*",lhs,rhs] => unaryForm2String x + strconc(multForm2String lhs,'"*", multForm2String rhs) + +divForm2String x == + x isnt ["/",lhs,rhs] => multForm2String x + strconc(divForm2String lhs,'"/", expForm2String rhs) + +remForm2String x == + x isnt ["rem",lhs,rhs] => divForm2String x + strconc(divForm2String lhs,'" rem ", multForm2String rhs) + +quoForm2String x == + x isnt ["quo",lhs,rhs] => remForm2String x + strconc(quoForm2String lhs,'" quo ", remForm2String rhs) + +plusForm2String x == + x isnt ["+",lhs,rhs] => quoForm2String x + strconc(plusForm2String lhs,'" + ", plusForm2String rhs) + +minusForm2String x == + x isnt ["-",lhs,rhs] => plusForm2String x + strconc(minusForm2String lhs,'" - ", minusForm2String rhs) + +inputForm2String x == + atom x => primaryForm2String x + [op,:args] := x + isUnaryPrefix op and #args = 1 => unaryForm2String x + #args = 2 => + op in '(** _^) => expForm2String x + op = "*" => multForm2String x + op = "/" => divForm2String x + op = "rem" => remForm2String x + op = "quo" => quoForm2String x + op = "+" => plusForm2String x + op = "-" => minusForm2String x + op in '(_@ _:_: $ pretend) => + typedForm2String(op, first args, second args) + callForm2String x + callForm2String x + +inputForm2OutputForm x == + INTERN inputForm2String x + |