dumpExpression.frink

Download or view dumpExpression.frink in plain text format


/** This dumps an expression as a tree. */

/** This sets up the recursive call. */
dumpExpression[expr] :=
{
   return dumpExpression[expr, 0, ""]
}

dumpExpression[expr, indent, index] :=
{
   type = type[expr]
   result = repeat[" ", indent*4] + (index ? index + ": " : "")  + type[expr]
   if type == "String"
      result = result + ": " + inputForm[expr]   // Do substring?
   if type == "Unit"
      result = result + ": $expr"
   if type == "Symbol"
      result = result + ": " + inputForm[expr]
   
   result = result + "\n"
   
   children = getChildCount[expr]
   
   for i=0 to children-1
      result = result + dumpExpression[getChild[expr, i], indent+1, toString[i]]

   return result
}

/*
println[dumpExpression[parseToExpression["2x^2 + 5x + 3"]]]
println[]

println[dumpExpression[parseToExpression["{|a is isInteger, b is isInteger = 0 | a + b^2}"]]]

println[dumpExpression[getFunction["arctan", 2]]]

println[dumpExpression[parseToExpression["c^2"]]]

c = [1,2,3]
println[dumpExpression[c]]

println[dumpExpression[parseToExpression["(a * b) / c"]]]

println[dumpExpression[newJava["java.math.BigInteger", ["100"]]]]
*/


Download or view dumpExpression.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19346 days, 22 hours, 11 minutes ago.