Skip to content

Instantly share code, notes, and snippets.

@master-q
Created December 23, 2011 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save master-q/1513996 to your computer and use it in GitHub Desktop.
Save master-q/1513996 to your computer and use it in GitHub Desktop.
例: Pascal のような repeat until
### http://www.jmuk.org/~mukai/camlp4tut.html#label-94
$ cat foo.ml
open Camlp4.PreCast
open Syntax
EXTEND Gram
GLOBAL: expr;
expr: LEVEL "top"
[[ "repeat"; e1 = expr; "until"; e2 = expr ->
<:expr< do { $e1$; while not $e2$ do { $e1$; } } >> ]];
END;;
$ cat bar.ml
let main () =
let i = ref 0 in
repeat print_int !i; incr i until !i = 10;
print_newline ()
let _ = main ()
$ cat make.sh
#!/bin/sh
rm -f *.cmi *.cmo
ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c foo.ml
ocamlc -pp "camlp4o foo.cmo" bar.ml
$ ./make.sh
$ ./a.out
0123456789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment