/usr/share/doc/ats-lang-anairiats-examples/examples/KernighanRitchie/Chapter01/wc.dats is in ats-lang-anairiats-examples 0.2.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | //
// K&R, 2nd edition, page 20
//
//
// Translated into ATS by Hongwei Xi (hwxi AT cs DOT bu DOT edu)
//
(*
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* count lines, words, and chars in input */
int main () {
int c, nl, nw, nc, state ;
state = OUT ;
nl = nw = nc = 0 ;
while ((c = getchar()) != EOF) {
++nc ;
if (c == '\n') ++nl ;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT ;
else if (state == OUT) {
state = IN ; ++nw ;
}
} // end of [while]
printf ("%d %d %d\n", nl, nw, nc) ;
} /* end of [main] */
*)
staload "libc/SATS/stdio.sats"
#define IN 0; #define OUT 1
implement main () = let
fun loop (nl: &int, nw: &int, nc: &int, state: &int): void = let
val c = getchar ()
in
if (c <> EOF) then let
val () = nc := nc + 1
val c = char_of_int (c)
val () = if (c = '\n') then (nl := nl + 1)
val () = case+ c of
| ' ' => state := OUT
| '\n' => state := OUT
| '\t' => state := OUT
| _ => begin
if (state = OUT) then (state := IN; nw := nw + 1)
end
in
loop (nl, nw, nc, state)
end else begin
// loop exits
end // end of [if]
end // end of [loop]
var nl: int = 0 and nw: int = 0 and nc: int = 0 and state: int = OUT
val () = loop (nl, nw, nc, state)
in
printf ("%d %d %d\n", @(nl, nw, nc))
end // end of [main]
(* ****** ****** *)
(* end of [wc.dats] *)
|