Just in time processing on a character stream: Difference between revisions

(added solution for c)
Line 666:
{{out}}
<pre>Silence-Dogood.</pre>
 
=={{header|Julia}}==
<lang julia>@enum streamstate GET_FF GET_LF GET_TAB GET_CHAR ABORT
 
function stream_decode_jit(iostream)
msg, state, ffcount, lfcount, tabcount, charcount = "", GET_FF, 0, 0, 0, 0
while true
if state == ABORT || eof(iostream)
return msg
end
ch = read(iostream, Char)
if state == GET_FF && ch == '\f'
ffcount += 1
state = GET_LF
lfcount = 0
elseif state == GET_LF && ch == '\n'
if (lfcount += 1) == ffcount
state = GET_TAB
tabcount = 0
end
elseif state == GET_TAB && ch == '\t'
if (tabcount += 1) == ffcount
state = GET_CHAR
charcount = 0
end
elseif state == GET_CHAR
if (charcount += 1) == ffcount
print(ch)
msg *= ch
if ch == '!'
state = ABORT
else
state = GET_FF
end
end
end
end
end
 
stream_decode_jit(open("filename.txt", "r"))
</lang>
 
 
 
 
 
 
 
=={{header|Kotlin}}==
4,105

edits