Guest User

Untitled

a guest
Feb 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. open Format
  2. open Camlp4.PreCast
  3.  
  4. let printer =
  5. let module P = Camlp4.Printers.OCaml.Make(Syntax)
  6. in new P.printer ()
  7.  
  8. let print e =
  9. printf "%s:@\n" (Loc.to_string (Ast.loc_of_expr e));
  10. printer#expr std_formatter e;
  11. printf "@\n"
  12. ;;
  13. let e = <:expr@here< 1 * 2 + 3 >> in
  14. print e;
  15.  
  16. print <:expr@here< 1 + 2 * 3 >>;
  17. print <:expr@here< 1 * 2 * 3 >>;
  18. print <:expr@here< 1 * 2 ** 3 >>;
  19.  
  20. print <:expr@here< 1 - 2 - 3 >>;
  21.  
  22. print <:expr@here< 1 + 2 * 3 / 4 >>;
  23.  
  24. print <:expr@here< 1 + 2 * 3 + 4 >>;
  25.  
  26. print <:expr@here< 1 * 2 + 3 * 4 >>;
  27.  
  28.  
  29. (* Local Variables: *)
  30. (* compile-command: "ocamlc -o test_expr -pp camlp4of -I +camlp4 camlp4lib.cma test_expr.ml && ./test_expr" *)
  31. (* End: *)
Add Comment
Please, Sign In to add comment