git @ Cat's Eye Technologies Tamsin / master eg / alg-expr3.tamsin
master

Tree @master (Download .tar.gz)

alg-expr3.tamsin @masterraw · history · blame

# This example Tamsin program was written by Chris Pressey, and is
# hereby placed in the public domain.  It comes with NO WARRANTY.

main = expr0 → E & walk(E).
expr0 = expr1 → E1 & {"+" & expr1 → E2 & E1 ← add(E1,E2)} & E1.
expr1 = term → E1 & {"*" & term → E2 & E1 ← mul(E1,E2)} & E1.
term = "x" | "y" | "z" | "(" & expr0 → E & ")" & E.
walk(add(L,R)) = walk(L) → LS & walk(R) → RS & return LS+RS+' +'.
walk(mul(L,R)) = walk(L) → LS & walk(R) → RS & return LS+RS+' *'.
walk(X) = return ' '+X.