|
|
# #use "interp.ml" ;; # let prog = Stmts (Assign ("x",Plus (Num 1,Times (Num 2,Num 3))), Stmts (Assign ("y",Div (Id "x",Num 4)), Print (Id "y"))) ;; # interp prog ;; 1 - : id -> int =
# let prog1 = Stmts (Assign ("y", StmtExp (Assign ("x", Plus (Num 1, Num 2)), Id "x")), Print (Id "y")) ;; # interp prog1 ;; 3
# let prog2 = Stmts (Assign ("y", StmtExp (Assign ("x", Plus (Num 1, Num 2)), Id "x")), Print (Id "x")) ;; # interp prog2 ;; Exception: No_such_symbol.
# interp prog2 ;; 3
calc
S -> E $ E -> id E -> id ( E ) E -> E + id
# #use "firstFollow.ml";; # let rule = [ ["S"; "E"; "$"]; ["E"; "id"]; ["E"; "id"; "("; "E"; ")"]; ["E"; "E"; "+"; "id"] ];; # firstFollow rule;; nullable(S):false nullable(E):false FIRST(S):id FIRST(E):id FOLLOW(S): FOLLOW(E):$ ) + - : unit = ()
simc sample.spl a.out
{ int x, rlt; rlt = 1; for (x = 0 .. 5) rlt = rlt * 3; iprint(rlt); }
peephole < tmp.s > opt.s gcc opt.s a.out