NAME
ccl —
cool char lang
DESCRIPTION
ccl is a brainfuck-inspired language,
Unlike in brainfuck, though, ccl manipulates the
stack, not the array. Also, each cell in ccl is a 16
bit signed integer with overflow allowed. Stack doesn't have size
limitations, though ram in your pc is still limited. All names in
ccl are limited to 1 character.
ccl has variables. There're
2 sets of variables: global and local ones. Local variables are different
for each
procedure.
As was stated before, there are procedures. Their names are stored separately from variables', so you can store both variable and function with the same name. Procedures are defined at runtime, and it's possible to overwrite them.
There're 3 types of instruction. First type is an instruction
without any argument. Its name can be simply put in the code. Second is an
instruction with an argument. Arguments are mandatory, meaning you cannot
omit them. Though, there's special variable with the name
_, but not every instruction will accept it. Third
type is a block. It's a pair of characters that stores some code between
them. Also, block accepts an argument on the left of left character.
Instructions that work with the stack will throw an uncatchable error if stack is too small.
They're 2 types of comments in ccl. The
first is a one line one: It starts with a /
character, and ends with a newline. The second is the multiline comment:
Text inside \ characters is not parsed. These
comments can't overlap, and you can safely put characters meaning one
comment type into another.
The instructions are as follows:
^- Takes no parameters. Pushes a new cell on the stack with the value 0.
+- Takes no parameters. Increments last cell on the stack.
-- Takes no parameters. Decrements last cell on the stack.
*- Takes no parameters. Pops last cell and then adds its value to a new last storing the result here.
~- Takes no parameters. Pops last cell and then subtracts its value from a new last storing the result here.
#- Takes no parameters. If called from a loop, exits it (like
‘
break’). If called from a procedure, exits it (like ‘return’). Otherwise (meaning called from outside of anything) exits the program. :- Takes no parameters. If called from a loop, skips current iteration,
acting like a ‘
continue’. %- Takes a parameter. Accepts
_. Reverses last n variables on the stack, where n is a value of a provided variable or size of the stack if_was provided. Variable with a given name must exist. =- Takes a parameter. Accepts
_. Pops last cell and then assigns (possibly overriding) its value to a given variable, or just pops if_was provided. !- Takes a parameter. Doesn't accept
_. Deletes variable of a given name. Prefers local ones first. Variable with a given name msut exist. $- Takes a parameter. Doesn't accept
_. Pushes given variable's value on the stuck. Variable with a given name must exist. &- Takes a parameter. Doesn't accept
_. Creates a local variable with a given name assigning 0 to it. If variable with a given name exists, overrides it to be 0. Note that every operation prefers local variables first. <- Takes a parameter, Doesn't accept
_. Prints the value of a given variable as an ascii(7) character. Variable with a given name must exist. >- Takes a parameter. Doesn't accept
_. Reads the character from the console, writing its value to a variable. Variable with a given name must exist. @- Takes a parameter. Doesn't accept
_. Calls a procedure with a given name. Procedure with a given name must exist. { }- Doesn't accept
_. Defines a procedure with a given name. May override. ( )- Accepts
_. Enters a condtional loop. Continues working until given variable is less then or equal to 0. Variable with a given name must exist. If a parameter is_, then acts as infinite loop. The behavior is unspecified when the variable used by this loop is deleted while unside. [ ]- Repeats its body n times where n is a value of a variable with a given name. Variable with a given name must exist.
? ;- Executes its body if a variable with a given name is equal to the last cell on the stack. Variable with a given name must exist.
EXAMPLES
This procedure calculates nth number of a fibonacci sequence, accepting the parameter and returning the result over last cell on the stack:
F {
/ define some local variables to work with
&a &b &c
/ if the parameter is either 0 or 1,
/ return with it
c? #; $c+ = c
c? #;
/ otherwise, get 2 previous numbers
/ of a sequence and sum them
= c $c $c
- @F = a
-- @F = b
$a $b*
}
SEE ALSO
AUTHORS
Original implementation is written by holy8, slightly patched and rewritten in mdoc(7) by Nakidai Perumenei <nakidai@disroot.org>