back to index

Identifiers, delimiters, keywords and constants

Basically, TKS uses the regular 7bit ASCII charset; support for UTF-8 (unicode) ist not available yet (but may be in future releases).

Escape-Sequences

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:

SequenceDescription
\\backslash
\'single quotation mark
\"double quotation mark
\nlinefeed
\rcarriage return
\ttabulator
\vvertical tabulator
\fform feed
\bbackspace
\aalert (beep/flash screen)
\eESC 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

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.

Delimiters and operators

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).

Reserved keywords

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

Literals

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];

User defined constants

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;

System constants

Following is a list of pre-defined system constants:
 
1PI
- 1 divided by PI
1SQRT2
- 1 divided by sqrt(2)
2PI
- PI multiplied by 2 (6.2..)
BIG_ENDIAN
- big endian byte order, msb first
default
- 0 or 0.0 or false
E
- the math constant E
false
- 0
SEEK_BEG
- stream seek mode
SEEK_CUR
- stream seek mode
SEEK_CUR
- stream seek mode
IOS_OUT
- input/output stream mode
IOS_IN
- input/output stream mode
IOS_INOUT
- input/output stream mode
null
- 0 Object pointer
LITTLE_ENDIAN
- little endian byte order, lsb first
LN10
- the math constant ln(10)
LOG10
- the math constant log(10)
PI
- the math constant PI
PI2
- PI divided by 2 (1.5..)
RAND_MAX
- maximum value returned by sirnd ASM opcode
SQRT2
- the math constant sqrt(2)
true
- 1
 


back to index

TkScript and the TkScript documentation are (c) Copyright 2001-2004 by Bastian Spiegel.