Basically, TKS uses the regular 7bit ASCII charset; support for UTF-8 (unicode) ist not available yet (but may be in future releases).
In order to include non-printable ASCII control codes (e.g. line feed) as well as special characters like ' or \ in Strings or character based integer literals, the following char sequences are supported:
Sequence | Description |
---|---|
\\ | backslash |
\' | single quotation mark |
\" | double quotation mark |
\n | linefeed |
\r | carriage return |
\t | tabulator |
\v | vertical tabulator |
\f | form feed |
\b | backspace |
\a | alert (beep/flash screen) |
\e | ESC character (decimal 27, octal 033). |
The latter sequence marks the beginning of ANSI control sequences. A rather comprehensive list of ANSI escape sequences can be found here: http://astronomy.swin.edu.au/~pbourke/dataformats/ansi.html
Note: The regular windows console emulator (command.com) and thus all shells based on it (e.g. CygWin) unfortunately do not support ANSI sequences (CygWin seems to be able to emulate ANSI sequences but you need to compile a native CygWin version of the tks.exe).
Identifiers are used to define unique names for variables, classes, functions and constants. Identifiers are case-sensitive which means that e.g. MyVariable and myvariable are clearly distinguished.
The first char of an identifier has to be a letter [a-zA-Z] or the underscore _; identifiers must not contain delimiters and operators; reserved keywords may also not be used as identifiers. The length is practically unlimited (memory, 24bit) but it should not exceed 128 characters.
TkScript uses a char-based scanner. The following chars separate words (tokens and identifiers):
= > < == <= >= != , ! && || ++ -- + - * / & | ^ % << >> += -= *= /= &= |= ^= %= <<= >>= ( ) { } [ ] ;
Additional delimiters are ASCII control characters like "\n" (newline) "\t" (tab) and " " (space).
The following character sequences must not be used as identifiers:
abs acos argb asin break case clamp class compile cos default #define define deref dtrace do else enum exp false float for function frac if int ln loop method module null Object Pointer prepare print private protected return rgb rnd round sin static String switch tag tan tcchar tcfloat tcobject tcstring this trace true typeid typename use var while wrap
These keywords are used for
The following forms of representation can be used to describe constant values:
10 : decimal integer 10.25 : (decimal) floating point number $fedcba98 : hexadecimal integer #fedcba98 : hexadecimal integer using the HTML colorformat (#aarrggbb, a=alpha, r=red, g=green, b=blue) 0b1101001 : binary integer '!' : a single ASCII char '\n' : a single ASCII escape sequence (ex. linefeed) "a \'string\'\n" : a sequence of one or more ASCII characters "\e[2J" : an ASCII escape sequence (ex. clear screen) String s= "hello, \n" "world"; : a multi-line character sequence s<=null; : the "null" literal. object references are unlinked by (pointer-)assigning 'null').Please notice that if you e.g. want to pass "big" numbers to number objects (Double etc..) you can wrap them in a String. This noticeably applies to 64bit fixed and floating point numbers.
Example:
trace "hello, world.";
int i=0b1101001;
float f=10.25;
String s="a \'string\'\n";
String s_clrscr="\e[2J";
String s_text="text*text*text*text*"
"text*text*text*text*"
"text*text*text*text*"
"text*text*text*text*"
"text*text*text*text*"
"text*text*text*text*"
;
int c='!';
int c2=s_text[9];
In order to improve readability, it is recommended to assign an unique name to frequently used constants so that the actual value of a constant is defined at exactly one location in the source code (typically in the header).
The statements define (#define) and/or enum (enumeration) are provided for this purpose.
The name of a constant must commence with a letter [a-zA-Z] or the underscore char. The succeeding characters may be letters, underscores or numbers [0-9].
Example:
#define NUMLOOPS 42 loop(NUMLOOPS) { /* ... */ }
Example:
#define DEG2RAD 0.00872664625997 trace "147.5 Grad im Bogenmaß entsprechen "+(147.5*DEG2RAD);
Example:
#define AUTHOR "Bastian Spiegel" trace "This software was developed by " + AUTHOR ;
Example:
enum { RED, GREEN, BLUE }; // => RED==0, GREEN==1, BLUE==2
Example:
enum { RED, GREEN=4, BLUE }; // => RED==0, GREEN==4, BLUE==5
Constants are always replaced by exactly one value; a programmable macro processor like in C is not available.
Please notice that class constants can be initialized using (complex) expressions. Example:
class CConst { define int A=1+3*4-2*3; define int SOL=A*6; }
print CConst.SOL;
Following is a list of pre-defined system constants:
|