CAOS language spec
From Creatures Wiki
This describes the known CAOS language as used in the Creatures Evolution Engine.
Contents |
[edit] basic token types
These are the types of tokens which can be present in CAOS source files.
- integer - any signed 32-bit integer, literals are capped at the limits not overflowed
- literals can be in binary, eg %010101
- literals can be characters, eg 'A' or '$'
- don't think you can have a ' as a char - escaping doesn't work
- float - any float (?)
- string - any string, enclosed in double-quotes, \", \\ and \n are valid (more?)
- bytestring - a bunch of bytes enclosed in square brackets, eg [1 2 15 255]
- you can use any integer as the values (so binary/characters are valid)
- function - four-character identifier representing a CAOS function
- label - as used by GSUB, GOTO and SUBR
[edit] additional parameter types
These are types which aren't in the above list but can be used as parameters or return values.
- anything - like it says, any type.
- decimal - either an integer or a float
- note that CAOS will cast integers to floats and vice versa when passing parameters. casting float to integer rounds.
- so decimal is only used when type needs preserving, eg for OUTV
- variable - a variable (ie, the result of VAxx/OVxx/etc)
- agent - an agent.
[edit] languageness
Tokens are normally separated by whitespace of some kind. Newlines are just treated as normal whitespace.
- commands can span several lines
- there can be several on a line.
However, there is no need for whitespace directly after a string, bytestring or decimal.
- This may be a bug in CEE. It's present in openc2e too for compatibility reasons.
CAOS source files are made up of CAOS commands (functions without a return value), one after another.
- eg: 'OUTV 1 OUTV %01011 OUTS "hello"'
Obviously you can use functions too.
- eg: 'SETV VA00 1 TARG PNTR ADDV VA00 UNID OUTV VA00'
- note it's impossible to work out when functions/commands start/end if you don't know their details
- this is why it's good for coders to keep one-command-per-line, although this isn't helpful *enough*
[edit] conditions
Conditions compare variables/literals. For instance, 'VA00 > 4'.
Condition operators: <> = >= > <= <
Text equivalents (can be used interchangably): NE EQ GE GT LE LT
- so 'VA00 GT 4' is equivalent to the above example.
You can join conditions together with 'AND' or 'OR'.
- eg: 'VA00 > 4 OR VA01 EQ 2'.
They're evaluated simply from left to right.
- 'a OR b AND c' means '(a OR b) AND c', not 'a OR (b AND c)'.
- you're stuck with this, brackets aren't allowed.
- this means you can step along one-at-a-time and just combine with the last result based on whether it was joined by an AND or OR.
- conditions do not short-circuit
When comparing integer and float, the integer is cast to float first (3.6 eq 4 is not true, but 4.0 eq 4 is).


