1 module List = ListLabels
13 | CompoundStm of stm * stm
14 | AssignStm of id * exp
15 | PrintStm of exp list
19 | OpExp of exp * binop * exp
20 | EseqExp of stm * exp
22 val maxargs : stm -> int
33 | CompoundStm of stm * stm
34 | AssignStm of id * exp
35 | PrintStm of exp list
39 | OpExp of exp * binop * exp
40 | EseqExp of stm * exp
42 (* 01.p.1: Write ML function (maxargs : stm -> int) that tells the
43 * maximum number of arguments of any print statement within any
44 * subexpression of a given statement. For example, maxargs(prog)
49 let rec check_stm = function
51 let exps_length = List.length exps in
52 if exps_length > !max then max := exps_length else ();
53 List.iter exps ~f:check_exp
56 | CompoundStm (s1, s2) ->
59 and check_exp = function
60 | IdExp _ | NumExp _ -> ()
61 | OpExp (e1, _, e2) ->
74 * b := (print(a, a - 1), 10 * a);
78 ( Spl.AssignStm ("a", Spl.OpExp (Spl.NumExp 5, Spl.Plus, Spl.NumExp 3))
85 ; Spl.OpExp (Spl.IdExp "a", Spl.Minus, Spl.NumExp 1)
87 , Spl.OpExp (Spl.NumExp 10, Spl.Times, Spl.IdExp "a")
90 , Spl.PrintStm [Spl.IdExp "b"]
95 Printf.printf "maxargs: %d\n" (Spl.maxargs spl_prog)