diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-04-27 10:19:54 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-04 15:23:59 -0700 |
| commit | 8ea9fc2536aa0eb45092ed3654dba19b0c8e7c20 (patch) | |
| tree | 4c11670239a6722836891f5750098c7582a44011 /syntax.sml | |
| parent | 5737e8430d43b3b5bd448f761cd2f3c35707a174 (diff) | |
| download | sml-8ea9fc2536aa0eb45092ed3654dba19b0c8e7c20.tar.zst | |
Implement recursive functions.
Diffstat (limited to 'syntax.sml')
| -rw-r--r-- | syntax.sml | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -27,7 +27,9 @@ struct | ELambda of pat * expr | ECase of expr * (pat * expr) list - and dec = DVal of pat * expr + and dec = + DVal of pat * expr + | DValRec of pat * expr (* Lambda language *) type var = int @@ -61,7 +63,7 @@ struct | VString of string datatype cexp = - CRecord of (value * int list) list * var * cexp + CRecord of ((value * int list) list * var) list * cexp | CSelect of int * value * var * cexp | CApp of value * value list | CFix of (var * var list * cexp) list * cexp @@ -131,6 +133,7 @@ struct and decToStringI (indent : string) (x : dec) : string = case x of DVal (p, e) => "DVal (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")" + | DValRec (p, e) => "DValRec (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")" val exprToString : expr -> string = exprToStringI "" @@ -171,7 +174,7 @@ struct val self = cexpToStringI indent val newIndent = indent ^ "\t" in case x of - CRecord (a, b, c) => "CRecord (" ^ listToString (fn (x, y) => "(" ^ valueToString x ^ ", " ^ listToString Int.toString y ^ ")") a ^ ", " ^ Int.toString b ^ ",\n" ^ indent ^ self c ^ ")" + CRecord (records, c) => "CRecord (" ^ listToString (fn (a, b) => listToString (fn (x, y) => "(" ^ valueToString x ^ ", " ^ listToString Int.toString y ^ ")") a ^ ", " ^ Int.toString b ^ ")") records ^ ",\n" ^ indent ^ self c ^ ")" | CSelect (a, b, c, d) => "CSelect (" ^ Int.toString a ^ ", " ^ valueToString b ^ ", " ^ Int.toString c ^ ",\n" ^ indent ^ self d ^ ")" | CApp (a, b) => "CApp (" ^ valueToString a ^ ", " ^ listToString valueToString b ^ ")" | CFix (a, b) => "CFix (" ^ multilineListToString (fn indent' => fn (x, y, z) => "(" ^ Int.toString x ^ ", " ^ listToString Int.toString y ^ ",\n" ^ indent' ^ "\t" ^ cexpToStringI (indent' ^ "\t") z) newIndent a ^ ",\n" ^ newIndent ^ cexpToStringI newIndent b ^ ")" |
