Created
December 23, 2011 12:04
-
-
Save master-q/1513996 to your computer and use it in GitHub Desktop.
例: Pascal のような repeat until
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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