From 4fe42be07b7b57147f9cac0d17c2611f71f0758a Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 18 May 2024 07:23:11 -0700 Subject: Add structures. --- syntax.sml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'syntax.sml') diff --git a/syntax.sml b/syntax.sml index e05beee..2f7a96e 100644 --- a/syntax.sml +++ b/syntax.sml @@ -12,7 +12,7 @@ struct | PVar of string | PInt of int | PTuple of pat list - | PCon of string * pat + | PCon of string list * pat datatype expr = EIdent of string list @@ -34,6 +34,7 @@ struct | DValRec of pat * expr | DFun of string * (pat list * expr) list | DDatatype of string * (string * etype option) list + | DStruct of string * dec list (* Lambda language *) type var = int @@ -127,7 +128,7 @@ struct | PVar v => "PVar " ^ quote v | PInt i => "PInt " ^ Int.toString i | PTuple pats => "PTuple " ^ listToString patToString pats - | PCon (con, v) => "PCon " ^ "(" ^ quote con ^ ", " ^ patToString v ^ ")" + | PCon (con, v) => "PCon " ^ "(" ^ listToString quote con ^ ", " ^ patToString v ^ ")" fun exprToStringI (indent : string) (x : expr) : string = let val self = exprToStringI indent @@ -153,6 +154,7 @@ struct | DValRec (p, e) => "DValRec (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")" | DFun (name, cases) => "DFun (" ^ quote name ^ ", " ^ multilineListToString (fn indent => fn (ps, b) => "(" ^ listToString patToString ps ^ ", " ^ exprToStringI indent b ^ ")") indent cases ^ ")" | DDatatype (name, arms) => "DDatatype (" ^ quote name ^ ", " ^ listToString (fn (con, v) => "(" ^ quote con ^ ", " ^ optionToString etypeToString v ^ ")") arms ^ ")" + | DStruct (name, decls) => "DStruct (" ^ quote name ^ ",\n" ^ indent ^ "\t" ^ multilineListToString decToStringI (indent ^ "\t") decls ^ ")" val exprToString : expr -> string = exprToStringI "" -- cgit v1.3.1