Appendix A: Keywords and Operator Precedence
A name in tiko is one of five things, and they follow different rules. A reserved word is never a name. A runtime name may not be reused at module level. A contextual word is a keyword only where its statement expects it. A fixed-width type name, like the constant nullptr, is predeclared and may be replaced. Everything else is free. The rules below were measured by compiling each word in each position with tiko and with fbc-modern 1.20, and the two give the same answer for every word in every position.
Reserved words (247)
A reserved word cannot name a variable, a constant or a procedure, at module level, inside a procedure or inside a namespace. Case does not matter. The diagnostic is usually TKO0600: '…' is already declared in this scope, because the word is declared by the language itself; where the word starts a statement of its own, the parser reports that statement's error instead.
__fastcall | cos | draw | let | print | tan |
__thiscall | cptr | dynamic | lib | private | then |
abs | cshort | else | line | procptr | threadcall |
abstract | csign | elseif | local | property | to |
access | csng | encoding | lock | protected | trim |
acos | cubyte | end | log | pset | type |
alias | cuint | endif | long | ptr | typeof |
and | culng | enum | longint | public | ubound |
andalso | culngint | eqv | loop | put | ubyte |
any | cunsg | erase | lprint | random | ucase |
append | cushort | err | lset | read | uinteger |
as | cva_arg | error | ltrim | redim | ulong |
asc | cva_copy | exit | mid | rem | ulongint |
asin | cva_end | exp | mkd | restore | union |
asm | cva_start | explicit | mki | resume | unlock |
atan2 | cvd | export | mkl | return | unsigned |
atn | cvi | extends | mklongint | rset | until |
base | cvl | extern | mks | rtrim | ushort |
binary | cvlongint | field | mkshort | sadd | using |
boolean | cvs | fix | mod | scope | ustring |
byref | cvshort | for | name | screen | va_first |
byte | data | frac | namespace | seek | var |
byval | declare | function | new | select | varptr |
call | defbyte | get | next | sgn | view |
case | defdbl | gosub | not | shared | virtual |
cast | defined | goto | on | shl | wchr |
cbool | defint | if | open | short | wend |
cbyte | deflng | iif | operator | shr | while |
cdbl | deflongint | imagecreate | option | sin | width |
cdecl | defshort | imp | or | single | window |
chr | defsng | implements | orelse | sizeof | winput |
cint | defstr | import | output | spc | with |
circle | defubyte | include | overload | sqr | write |
class | defuint | input | paint | static | wstr |
clng | defulng | instr | palette | stdcall | wstring |
clngint | defulongint | instrrev | pascal | step | xor |
close | defushort | int | peek | str | zstring |
color | delete | integer | point | string | |
common | destructor | is | pointer | strptr | |
const | dim | lbound | poke | sub | |
constructor | do | lcase | preserve | swap | |
continue | double | len | preset | tab |
The list includes every statement and function word of the classic language — print, open, len, read, name, width, lock — and every built-in type name, double and string included. function Double( ) is refused, and so is a variable called read.
Keywords as field names
A field may be named by most reserved words, because a field's name is only ever read after . or ->, or in its type's body. A type can have a field called name, type, len or constructor, and t.name reads it. The exceptions:
- The operator words
and,andalso,eqv,imp,mod,not,or,orelse,shl,shrandxor, anddeleteandnew, are never field names. - In the type-first spelling,
as T name,const,ptrandpointerare part of the type, not a name;ptr as longis a field. - In the name-first spelling,
name as T, the declaration wordsconst,declare,dim,enum,redim,static,private,protectedandpublicstart a declaration instead, andtypeandunioncannot take array bounds (type( 0 to 2 ) as long). - In the type-first spelling,
aliasis not a name either.alias as longis fine. remstarts a comment where a statement can end, sorem as longis a comment.as long remdeclares a field namedrem, andt.remreads it.
Runtime names (104)
These are the runtime library's procedures. They are not reserved words. The runtime declares them in the global namespace, so a declaration of the same name at module level collides with it: TKO0813: '…' is already declared by the runtime library. That covers a variable, a constant, a procedure, a for counter, a local inside a module-level procedure, and a parameter of a procedure's definition. The same name is fine inside a namespace or a method, as a field, a member procedure or an enum member, and as a parameter of a prototype.
allocate | csrlin | fre | multikey | rnd | settime |
beep | curdir | freefile | mutexcreate | run | shell |
bload | date | getjoystick | mutexdestroy | screencopy | space |
callocate | deallocate | getkey | mutexlock | screenevent | stop |
chain | dylibfree | imageconvertrow | mutexunlock | screenlist | system |
chdir | dylibload | imagedestroy | out | screenlock | threadcreate |
clear | environ | inkey | pcopy | screenptr | threadwait |
cls | eof | inp | pmap | screenres | time |
command | erfn | kill | pointcoord | screenset | timer |
condbroadcast | erl | loc | pos | screensync | wait |
condcreate | ermn | locate | randomize | screenunlock | windowtitle |
conddestroy | exec | lof | reallocate | setdate | wspace |
condsignal | exepath | lpos | reset | setenviron | |
condwait | flip | mkdir | rmdir | setmouse |
These also take a new overload: sub Hex( ) compiles beside the runtime's hex, but dim as long hex does not.
bin | getmouse | oct | screeninfo | vallng | whex |
bsave | hex | right | sleep | valuint | woct |
dir | imageinfo | screencontrol | val | valulng | |
dylibsymbol | left | screenglproc | valint | wbin |
#define is the exception: tiko accepts #define run 5, where fbc refuses it as a duplicated definition (Appendix D).
Contextual words
FBC-Modern's extensions added these words without reserving them, so existing code that uses them as names keeps compiling. Each one is a keyword only in the position shown, and an ordinary name everywhere else: each one compiles as a variable, a procedure, a field, a local and a namespace member.
| Word | A keyword in |
|---|---|
channel | select channel (Chapter 23) |
defer | defer statement, when a name, a keyword other than as, or the end of the statement follows (Chapter 6) |
each | for each (Chapter 20) |
from | case receive v from ch in select channel |
in | for each x in … |
match | match x followed by case arms or pattern => value arms, closed by end match (Chapter 6) |
of | type arguments: Array( of int32 ) (Chapter 17) |
override | after a method's declaration: declare sub M( ) override (Chapter 14) |
partial | partial type and partial class, one type in several blocks (Chapter 15) |
receive | case receive in select channel |
send | case send v to ch in select channel |
spawn | spawn Proc( args ) (Chapter 23) |
timeout | case timeout ms in select channel |
Fixed-width type names
tiko predeclares twelve type names that fbc does not have. Ten are typedefs for built-in types; int128 and uint128 are 128-bit integer types of tiko's own, C's __int128 (Chapter 4). None is a reserved word: a program's own declaration of one of them replaces tiko's without a diagnostic, so code that already declares INT32 — as win/basetsd.bi does — compiles unchanged.
| Name | Same type as | Name | Same type as |
|---|---|---|---|
int8 | byte | uint8 | ubyte |
int16 | short | uint16 | ushort |
int32 | long | uint32 | ulong |
int64 | longint | uint64 | ulongint |
float32 | single | float64 | double |
int128 | its own type | uint128 | its own type |
The predeclared constant
tiko predeclares one constant that fbc does not have, const nullptr as any ptr = 0: the null pointer, as a pointer (Chapter 11). It is replaced on the same terms as the type names above, so a program's own nullptr — fbc's own test suite has a field by that name — compiles unchanged.
Operator precedence
Tightest first. Operators on one row bind equally, and every binary operator is left-associative, ^ included. The member operators . and ->, calls ( ) and indexing [ ] bind tighter than everything here.
| Level | Operators |
|---|---|
| 1 | ^ |
| 2 | - (sign) + (sign) |
| 3 | * / |
| 4 | \ |
| 5 | mod |
| 6 | shl shr |
| 7 | + - |
| 8 | is & |
| 9 | = <> < <= > >= |
| 10 | not |
| 11 | and |
| 12 | or |
| 13 | imp eqv xor |
| 14 | orelse andalso |
The table is FreeBASIC's, measured operator pair by operator pair against fbc, and several rows differ from C and from intuition (Chapter 5). Each line below prints the same with tiko and with fbc-modern:
2 ^ 3 ^ 2 64 ^ is left-associative: (2 ^ 3) ^ 2
-2 ^ 2 -4 ^ binds tighter than the sign
1 shl 2 + 1 5 shl binds tighter than +, unlike C's <<
8 \ 4 * 2 1 * binds tighter than \: 8 \ (4 * 2)
2 * 3 mod 4 2 mod is looser than * and \
12 or 10 xor 6 8 or binds tighter than xor
1 or 2 and 0 1 and binds tighter than or
0 andalso 1 orelse 1 -1 andalso and orelse share one level
not 1 = 0 -1 not is looser than the comparisons: not (1 = 0)
not 0 and 3 3 ...and tighter than and: (not 0) and 3
& binds looser than + and -, so "a" & 1 + 2 means "a" & (1 + 2), and both compilers print a3.