diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2023-02-12 15:37:25 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2023-02-12 15:37:25 -0800 |
| commit | d940187fd8720e0ab3c00e5a6a7ae8f181c7752d (patch) | |
| tree | 69df829ae1e7fb9454008920b49db08489d939a6 /syntax.sml | |
| parent | 5989629a7951e544ad4656672025a99ecd08c7c9 (diff) | |
| download | sml-d940187fd8720e0ab3c00e5a6a7ae8f181c7752d.tar.zst | |
Add lambda functions.
Diffstat (limited to 'syntax.sml')
| -rw-r--r-- | syntax.sml | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -17,19 +17,22 @@ struct | EAndAlso of expr * expr | EOrElse of expr * expr | ELet of dec list * expr + | ELambda of expr and dec = DVal of expr (* Lambda language *) + type var = int datatype primop = PExit - datatype lexp = LApp of lexp * lexp + datatype lexp = LVar of var + | LFn of var * lexp + | LApp of lexp * lexp | LInt of int | LString of string | LRecord of lexp list | LPrim of primop (* CPS *) - type var = int datatype value = VVar of var | VLabel of var | VInt of int @@ -83,6 +86,7 @@ struct | EAndAlso (a, b) => "EAndAlso (" ^ self a ^ ", " ^ self b ^ ")" | EOrElse (a, b) => "EOrElse (" ^ self a ^ ", " ^ self b ^ ")" | ELet (decs, e) => "ELet (" ^ multilineListToString decToStringI indent decs ^ ", " ^ self e ^ ")" + | ELambda e => "ELambda " ^ exprToStringI indent e end and decToStringI (indent : string) (x : dec) : string = @@ -99,7 +103,9 @@ struct fun lexpToString (x : lexp) : string = case x of - LApp (a, b) => "LApp (" ^ lexpToString a ^ ", " ^ lexpToString b ^ ")" + LVar v => "LVar " ^ Int.toString v + | LFn (arg, expr) => "LFun (" ^ Int.toString arg ^ ", " ^ lexpToString expr ^ ")" + | LApp (a, b) => "LApp (" ^ lexpToString a ^ ", " ^ lexpToString b ^ ")" | LInt i => "LInt " ^ Int.toString i | LString s => "LString " ^ quote s | LRecord l => "LRecord " ^ listToString lexpToString l |
