Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

__fastcallcosdrawletprinttan
__thiscallcptrdynamiclibprivatethen
abscshortelselineprocptrthreadcall
abstractcsignelseiflocalpropertyto
accesscsngencodinglockprotectedtrim
acoscubyteendlogpsettype
aliascuintendiflongptrtypeof
andculngenumlongintpublicubound
andalsoculnginteqvloopputubyte
anycunsgeraselprintrandomucase
appendcushorterrlsetreaduinteger
ascva_argerrorltrimredimulong
asccva_copyexitmidremulongint
asincva_endexpmkdrestoreunion
asmcva_startexplicitmkiresumeunlock
atan2cvdexportmklreturnunsigned
atncviextendsmklongintrsetuntil
basecvlexternmksrtrimushort
binarycvlongintfieldmkshortsaddusing
booleancvsfixmodscopeustring
byrefcvshortfornamescreenva_first
bytedatafracnamespaceseekvar
byvaldeclarefunctionnewselectvarptr
calldefbytegetnextsgnview
casedefdblgosubnotsharedvirtual
castdefinedgotoonshlwchr
cbooldefintifopenshortwend
cbytedeflngiifoperatorshrwhile
cdbldeflongintimagecreateoptionsinwidth
cdecldefshortimporsinglewindow
chrdefsngimplementsorelsesizeofwinput
cintdefstrimportoutputspcwith
circledefubyteincludeoverloadsqrwrite
classdefuintinputpaintstaticwstr
clngdefulnginstrpalettestdcallwstring
clngintdefulongintinstrrevpascalstepxor
closedefushortintpeekstrzstring
colordeleteintegerpointstring
commondestructorispointerstrptr
constdimlboundpokesub
constructordolcasepreserveswap
continuedoublelenpresettab

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, shr and xor, and delete and new, are never field names.
  • In the type-first spelling, as T name, const, ptr and pointer are part of the type, not a name; ptr as long is a field.
  • In the name-first spelling, name as T, the declaration words const, declare, dim, enum, redim, static, private, protected and public start a declaration instead, and type and union cannot take array bounds (type( 0 to 2 ) as long).
  • In the type-first spelling, alias is not a name either. alias as long is fine.
  • rem starts a comment where a statement can end, so rem as long is a comment. as long rem declares a field named rem, and t.rem reads 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.

allocatecsrlinfremultikeyrndsettime
beepcurdirfreefilemutexcreaterunshell
bloaddategetjoystickmutexdestroyscreencopyspace
callocatedeallocategetkeymutexlockscreeneventstop
chaindylibfreeimageconvertrowmutexunlockscreenlistsystem
chdirdylibloadimagedestroyoutscreenlockthreadcreate
clearenvironinkeypcopyscreenptrthreadwait
clseofinppmapscreenrestime
commanderfnkillpointcoordscreensettimer
condbroadcasterllocposscreensyncwait
condcreateermnlocaterandomizescreenunlockwindowtitle
conddestroyexeclofreallocatesetdatewspace
condsignalexepathlposresetsetenviron
condwaitflipmkdirrmdirsetmouse

These also take a new overload: sub Hex( ) compiles beside the runtime's hex, but dim as long hex does not.

bingetmouseoctscreeninfovallngwhex
bsavehexrightsleepvaluintwoct
dirimageinfoscreencontrolvalvalulng
dylibsymbolleftscreenglprocvalintwbin

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

WordA keyword in
channelselect channel (Chapter 23)
deferdefer statement, when a name, a keyword other than as, or the end of the statement follows (Chapter 6)
eachfor each (Chapter 20)
fromcase receive v from ch in select channel
infor each x in …
matchmatch x followed by case arms or pattern => value arms, closed by end match (Chapter 6)
oftype arguments: Array( of int32 ) (Chapter 17)
overrideafter a method's declaration: declare sub M( ) override (Chapter 14)
partialpartial type and partial class, one type in several blocks (Chapter 15)
receivecase receive in select channel
sendcase send v to ch in select channel
spawnspawn Proc( args ) (Chapter 23)
timeoutcase 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.

NameSame type asNameSame type as
int8byteuint8ubyte
int16shortuint16ushort
int32longuint32ulong
int64longintuint64ulongint
float32singlefloat64double
int128its own typeuint128its 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.

LevelOperators
1^
2- (sign) + (sign)
3* /
4\
5mod
6shl shr
7+ -
8is &
9= <> < <= > >=
10not
11and
12or
13imp eqv xor
14orelse 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.