CamelCase in Roco
Example for versions
Roco 20071014
The example is commented in detail. Coroutine char
reads characters from standard input one by one and checks whether they are letters. Coroutine letter
is called for characters which turned out to be letters; it converts them into required case and prints them. Note that not
command inverts all bits of the number, so it can’t be used to negate a logical value (which is stored as 0 or 1) — one has to subtract this value from 1.
/* [0] - current character
[1] - last character was space?
rest are temporary variables (used within one iteration only)
*/
co letter{
/* coroutine to process the case of a known letter */
/* if it is uppercase, and last one was letter, change to lowercase */
sub [4] 1 [1]
and [5] [2] [4]
if [5]
add [0] [0] 32
/* if it is lowercase, and last one was space, change to uppercase */
and [5] [3] [1]
if [5]
sub [0] [0] 32
/* print the character */
cout [0]
set [1] 0
ac
}
co char{
/* read next character to [0] */
cin [0]
/* break the loop when the next character is end-of-line (ASCII 10) */
eq [2] [0] 10
if [2] ac
/* check whether this character is a letter at all [2] - uppercase, [3] - lowercase, [4] - at all, [5]-[6] - temporary */
/* uppercase */
gt [5] [0] 64
lt [6] [0] 91
and [2] [5] [6]
/* lowercase */
gt [5] [0] 96
lt [6] [0] 123
and [3] [5] [6]
/* at all */
or [4] [2] [3]
sub [5] 1 [4]
/* if this is not a letter, ONLY change [1] */
if [5]
set [1] 1
/* otherwise, call the coroutine to handle this */
if [4]
ca letter
}
/* at the start mark that last character was space */
set [1] 1
ca char
ac
Comments
]]>blog comments powered by Disqus
]]>