Skip to content

Files

Latest commit

 

History

History
57 lines (54 loc) · 4.47 KB

sexpr-to-str-translation.txt

File metadata and controls

57 lines (54 loc) · 4.47 KB

How to translate S-Expr into ST or in vice-versa

when met an atom in s-expr

  1. if it matches as a built-in ===> transform-to-st.
  2. else,
    1. if it is 1st item in the list,
      • (funcall (ref ..) (cdr ..))
    2. else,
      • (ref ..)

Built-ins and its translation-table.

ST-names-expr-atomST-paramss-expr-syn example
BoolValtrue -or- false
NullValnil
NumberVal(nums)
StringVal(strs)
FunctionValfnparams, body(fn [x y] (+ x y))
Prog1prog1body(prog1 ,@body)
ProgNprognbody(progn ,@body)
ParProgparprogbody(parprog ,@body)
LogAndlog-andparams(log-and a b c)
LogOrlog-orparams(log-or a b c)
LogNotlog-notparam(log-not a)
ArithAdd+params(+ a b c)
ArithSub-params(- a b c)
ArithMult*params(* a b c)
ArithMultMult**params(** a b c)
ArithDiv/params(/ a b c)
ArithDivDiv//params(// a b c)
ArithRemremparams(rem a b c)
ComparLt<params(< a b c)
ComparLe<=params(<= a b c)
ComparGt>params(> a b c)
ComparGe>=params(>= a b c)
Equaleq?params(== a b c)
NotEqualne?params(!= a b c)
IsNullnull?param(null? a)
IsNotNullnot-null?param(not-null? a)
Assignsetdst, src(set dst src)
AssignUpvarset^dst, src(set^ dst src)
AssignGlobalset/dst, src(set/ dst src)
Constconstdst, src(const dst src)
Letletexprs, body(let [(set x 42)] ,@body)
Ref(n/a)
Passpass(pass)
Funcallfncall or (n/a)fun, params(fncall my-fun [1 2 3])
(my-fun 1 2 3)
IfThenElseifcond, then, else(if ,cond ,then ,else)
Whenwhencond, then(when ,cond ,then)
Unlessunlesscond, then(unless ,cond ,then)
CaseElsecasev, case-items, else(case v [,@case-items] ,else)
CaseItem(n/a)v, then(v ,then)
CondElsecondcond-items, else(cond [,@cond-items] ,else)
CondItem(n/a)cond, then(,cond ,then)