Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crsn/examples/buf_io_frequency_analysis.csn

51 lines
1.2 KiB

(
; Perform frequency analysis of the input stream. Pipe a file to this program.
(def MINCH 33) ; lowest counted char
(def MAXCH 126) ; highest counted char
(sym tab r7)
(mkbf tab 128)
(sym ch r6)
(sym sum r1)
(sym max r2)
(:rch)
(ld ch @cin (eof? (j :rch_end)))
(rcmp ch MINCH MAXCH (ne? (j :rch)))
(bfrd r0 @tab ch)
(inc r0) (inc sum)
(cmp r0 max (>? (ld max r0)))
(bfwr @tab ch r0)
(j :rch)
(:rch_end)
(sym fac r3)
(div fac 100_000 max)
(ld ch MINCH)
(:print)
(bfrd r0 @tab ch)
(cmp r0 max
(eq?
(ld @cout 27) (ld @cout '[') (ld @cout '3') (ld @cout '2') (ld @cout 'm'))
)
(tst r0 (z? (j :print_next)))
(mul r0 fac)
(div r0 1000)
(ld @cout ch)
(ld @cout ' ')
(call bar r0)
(:print_next)
(ld @cout 27) (ld @cout '[') (ld @cout 'm')
(inc ch)
(cmp ch MAXCH (le? (j :print)))
(proc bar/1
(ld r0 arg0)
(:bar)
(ld @cout '#')
(dec r0 (nz? (j :bar)))
(ld @cout '\n')
(ret)
)
)