| home | contents | previous | next page | send comment | send link | add bookmark |

9. Language reference

This section contains descriptions of key words and standard identifiers used in the T programming language.

conventions

Italicized items are elements of code determined by the programmer. Bracketed [items] are optional. Items in braces {item} may be repeated. A bar | means that either the word on the right or the word on the left is applicable.

definitions

abs standard function
usage: abs(expn : int|real) : int|real
remarks: Function returns the absolute value of expn. The return type has same type as expn .
and keyword
usage: boolean expn and boolean expn
remarks: Operator returns a boolean value:
x       y       x and y
false   false   false
false   true    false
true    false   false
true    true    true
arccos standard function
usage: arccos(expn : real) : real
remarks: Function returns the real arc cosine of expn in units of radians. The value of expn must be in the range -1.0 to +1.0 or a run-time error will occur.
arcsin standard function
usage: arcsin(expn : real) : real
remarks: Function returns the real arc sine of expn in units of radians. The value of expn must be in the range -1.0 to +1.0 or a run-time error will occur.
arctan standard function
usage: arctan(expn : real) : real
remarks: Function returns the real arc tangent of expn in units of radians in the range of -π/2 to π/2.
arctanxy standard function
usage: arctanxy(x : real, y : real) : real
remarks: Function returns the real arc tangent of y/x in units of radians in the range of -π to π. If both x and y are 0.0 a run-time error will occur.
array keyword
usage: array(size{, size }) of type spec
remarks: Keyword is used for specifying a data type as an array of type spec. Array indices, size, must be constant integer expressions.
assert keyword
usage: assert boolean expn
remarks: Keyword is used to conditionally continue execution of a program. If boolean expn is false the program halts.
boolean keyword
usage: var name : boolean
remarks: Standard data type specifier. Boolean data can have a value of either true or false.
case keyword
usage:
case expn  of
    value constant{, constant} : 
        declarations and statements
   {value constant{, constant} : 
        declarations and statements}
   [value : 
        declarations and statements]
end case
remarks: The case expn and each constant must be of matching types of int, string, char, or enum. One value not having a constant may be placed at the end of the sequence of case values as a default branch.
ceil standard function
usage: ceil(expn : real) : int
remarks: Function returns the smallest integer greater than or equal to expn . See also: floor, round
char keyword
usage:
const name : char := 'literal character' 
var name : char
remarks: Standard data type specifier for characters
chr standard function
usage: chr(expn : int) : char
remarks: Function returns a character corresponding to the ASCII code of expn . See also: ord
close standard function
usage: close(stream : int) : boolean
remarks: Function closes the file associated with stream. Returns true on success or else false. See also: open
const keyword
usage: const name : type spec := constant expn
remarks: Keyword is used to declare a constant. The constant expn may not include any names of variables.
continue keyword
usage: continue [when boolean expn]
remarks: Used to jump to the start of the nearest enclosing for or loop statement. Jump is immediate unless the optional when condition is included.
cos standard function
usage: cos(expn : real) : real
remarks: Function returns the cosine of expn . The value of expn is assumed to be in units of radians.
cosh standard function
usage: cosh(expn : real) : real
remarks: Function returns the hyperbolic cosine of expn . The value of expn is assumed to be in units of radians.
cursor standard procedure
usage: cursor(shape : int)
remarks: Sets the cursor shape according to the following:
no cursor     - 0
normal cursor - 1
solid cursor  - 2
See also: locate
decreasing keyword
usage: for decreasing name := begin...end do
remarks: The keyword indicates that the for loop counter decrements. See also: for
div keyword
usage: integer expn div integer expn
remarks: Operator returns the quotient for integer division. The result type is integer. See also: mod
do keyword
usage: for name := begin...end do
remarks: See for.
elsif keyword
usage:
elsif boolean expn then 
    declarations and statements 
remarks: See if.
else keyword
usage:
else 
    declarations and statements 
end if 
remarks: See if.
end keyword
usage:
end loop
end for
end if
end case
end program
end name
end record
end union
remarks: Used to mark the end of logic statements and subprograms.
enum keyword
usage: type name : enum(item {, item })
remarks: Used to define an enumerated data type. Values are accessed using the form: name.item
eof standard function
usage: eof(stream : int) : boolean
remarks: Function returns true if the end of the file corresponding to stream has been reached. The value of stream is normally obtained using the open function.
erealstr standard function
usage:
erealstr(expn  : real, 
          format width : int,
          fraction width : int,
          exponent width : int) : string
remarks: Function returns a string of the form:
{blank}[-]digit.{digit} e sign digit{digit}
corresponding to expn. Widths are increased automatically if necessary. See also: frealstr, realstr, intstr
exit keyword
usage: exit [when boolean expn]
remarks: Used to exit from the nearest enclosing for or loop statement. Exit is immediate unless the optional when condition is included.
exp standard function
usage: exp(expn : real) : real
remarks: Function returns base raised to the value of expn .
false keyword
usage: name := false
remarks: Boolean constant; opposite of true.
floor standard function
usage: floor(expn : real) : int
remarks: Function returns the largest integer less than or equal to expn. See also: ceil, round
for keyword
usage:
for [decreasing] name := begin...end do
    declarations and statements
end for
remarks: The for statement repeats the list of declarations and statements for each value in the range begin...end. The identifier name must be declared as an integer outside the loop. The value of name is incremented, or decremented if the optional keyword decreasing is used, before repeating the loop. The continue and exit statements can be used for control within the loop. Declarations made within the loop are not visible outside the loop.
frealstr standard function
usage:
frealstr(expn  : real, 
         format width : int,
         fraction width : int) : string 
remarks: Function returns a string of the form:
{blank}[-]digit{digit}.{digit} 
corresponding to expn. Blanks are added as needed to right justify the string. Widths are increased automatically if necessary. See also: erealstr, realstr, intstr
function keyword
usage:
function name[(param{, param})] : type spec
    declarations and statements
end name
in which param is:
[var] name{, name} : type spec
remarks: A function must return a value using a return statement. Declarations within the function definition are only visible within the function. The use of var in a parameter list means that the parameter is to be passed to the function by reference rather than by value.
get keyword
usage:
get [:stream,] get item{, get item} 
in which a get item is one of:
a. name           - variable reference 
b. name : *       - line input 
c. name : width   - string input 
remarks: If stream is omitted, input is from the console. The name of get item must correspond to a variable. Form (a) can be an integer, real number, or a string. Forms (b) and (c) must be for a string variable.
getexp standard function
usage: getexp(expn : real) : real
remarks: Function returns the exponent, base 10, of expn. If expn equals 0.0, zero is returned. See also: setexp
getkey standard function
usage: getkey : int
remarks: Function returns an integer value corresponding to the key that was pressed. If a character key was pressed, the ASCII code is returned. If a function key was pressed, a value equal to the scan code plus 256 is returned. The key is not echoed to the video display. See section 10 for a table of key codes.
goto keyword
usage: goto label name
remarks: This keyword causes an immediate jump to the location of label name. Program execution may not jump from one subprogram to another. See also: label
if keyword
usage:
 if boolean expn then 
     declarations and statements 
{elsif boolean expn then 
     declarations and statements} 
[else 
     declarations and statements] 
 end if 
remarks: The declarations and statements are executed in the first branch in which the boolean expn is true. Optional elsif branches must be placed ahead of the single optional else branch. Declarations within each branch are not visible outside the branch.
include keyword
usage: include filename
remarks: Keyword is used to include an additional file in a program at the statement location.
index standard function
usage: index(str, pattern : string) : int
remarks: Function returns the value of the location of the first occurrence of pattern in str. If no match is found, a negative number is returned.
int keyword
usage:
var name : int 
const name : int := integer expn 
remarks: Standard data type specifier. Integer data can have values in the range given in section 10.
intreal standard function
usage: intreal(expn : int) : real
remarks: Function returns the real number value equivalent to expn .
intstr standard function
usage: intstr(expn, format width : int) : string
remarks: Function returns a string of form:
{blank}[-]digit{digit}
corresponding to expn. Blanks are added as needed to right justify the string. The width is increased automatically if necessary. See also: erealstr, frealstr, realstr
label keyword
usage: label name :
remarks: This keyword is used to declare a target for a goto statement.
length standard function
usage: length(expn : string) : int
remarks: Function returns the number of characters in expn .
ln standard function
usage: ln(expn : real) : real
remarks: Function returns the natural logarithm of expn which must have a value greater than zero or a run-time error will occur.
locate standard procedure
usage: locate(row, column : int)
remarks: Procedure positions the text mode cursor. The normal ranges are:
row     - 0 to 24 
column  - 0 to 79 
(see your system manual)
log10 standard function
usage: log10(expn : real) : real
remarks: Function returns the base 10 logarithm of expn which must have a value greater than zero or a run-time error will occur.
log2 standard function
usage: log2(expn : real) : real
remarks: Function returns the base 2 logarithm of expn which must have a value greater than zero or a run-time error will occur.
loop keyword
usage:
loop 
    declarations and statements
end loop
remarks: This keyword marks the beginning and end of an infinite loop. Declarations within the loop are not visible outside the loop. Statements in the loop are executed until terminated by an exit statement. A continue statement may also be used for control within the loop.
max standard function
usage: max(expn ,expn : int|real) : int|real
remarks: Function returns the maximum of two expns. If both are integers, an integer is returned; otherwise a real number is returned. See also: min.
min standard function
usage: min(expn ,expn :int|real) : int|real
remarks: Function returns the minimum of two expns. If both are integers, an integer is returned; otherwise a real number is returned. See also: max.
mod keyword
usage: integer expn mod integer expn
remarks: Operator returns the remainder for integer division. The result is an integer. See also: div.
nand keyword
usage: boolean expn nand boolean expn
remarks: Operator returns a boolean value:
x       y       x nand y
false   false   true
false   true    true
true    false   true
true    true    false
nor keyword
usage: boolean expn nor boolean expn
remarks: Operator returns a boolean value:
x       y       x nor y
false   false   true
false   true    false
true    false   false
true    true    false
not keyword
usage: not boolean expn
remarks: Operator returns a boolean value:
x       not x
false   true
true    false
of keyword
usage:
case expn of
array() of type spec
remarks: See array and case.
open standard function
usage: open(filename, mode : string) : int
remarks: Function opens a file for reading or writing and returns the file's stream number. The mode is "r" for reading from, or "w" for writing to. If the file cannot be opened, zero is returned. A standard printer can be opened using:
open("prn", "w") 
Device codes "lpt1" or "lpt2" can be used instead.
or keyword
usage: boolean expn or boolean expn
remarks: Operator returns a boolean value:
x       y       x or y
false   false   false
false   true    true
true    false   true
true    true    true
ord standard function
usage: ord(expn : char) : int
remarks: Function accepts a character and returns its corresponding ASCII code. See also: chr
pred standard function
usage: pred(expn : int|enum type) : int|enum type
remarks: Function accepts an integer or enumeration value and returns the previous value. See also: succ
procedure keyword
usage:
procedure name[(param{, param})] 
    declarations and statements
end name
in which param is:
[var] name{, name} : type spec
remarks: A procedure may return after reaching the end of the list of its statements or when a return statement is reached. Declarations within the procedure definition are only visible within it. The use of var in a parameter list means that the parameter is to be passed by reference.
program keyword
usage:
program
    declarations and statements 
end program
remarks: A program statement defines the start and end of the main program. Statements can call functions or procedures. Declarations are only visible within the program statement.
put keyword
usage:
put [:stream,] put item{, put item}[...] 
in which a put item is:
expn[:format width[:fraction width[:exponent width]]] 
remarks: If stream is omitted, output is to the console. A new line is started at the end of the list of put items unless ellipses "..." are appended.
putch standard procedure
usage: putch(expn : char, foreground, background : int)
remarks: This procedure puts a character at the location of the video cursor using the selected video textmode foreground and background colors. See section 10 for a table of video color codes.
putline standard procedure
usage: putline(x1, y1, x2, y2, color : int)
remarks: This procedure draws a straight line from x1, y1 through x2, y2 in the selected color. The endpoints of the line must be within the limits for the current graphics mode. See section 10 for a table of video color codes.
putpixel standard procedure
usage: putpixel(x, y, color : int)
remarks: This procedure places a video dot at location x, y in the selected color. The location must be within the limits for the graphics mode. See section 10 for a table of video color codes.
putstr standard procedure
usage: putstr(s : string, foreground : background : int)
remarks: This procedure puts a string s at the current location of the video cursor using the selected video textmode foreground and background colors. See section 10 for a table of video color codes.
rand standard function
usage: rand : real
remarks: Function returns the next value of a sequence of pseudo random real numbers approximating a uniform distribution within the range 0.0 to 1.0
randint standard function
usage: randint(low, high : int) : int
remarks: Function returns the next value of a sequence of pseudo random integers approximating a uniform distribution in the range low to high.
randomize standard procedure
usage: randomize
remarks: Procedure sets the pseudo random seed used by functions rand and randint to a machine generated random value.
randseed standard procedure
usage: randseed(new seed : int)
remarks: Procedure resets the pseudo random seed used by functions rand and randint to new seed.
real keyword
usage:
var name : real 
const name : real := expn 
remarks: Standard data type specifier for real numbers which can have values in the range given in section 10.
realstr standard function
usage: realstr(expn : real, format width : int) : string
remarks: Function returns a string of the form:
{blank}[-]digit{digit}.{digit} 
or of the form:
{blank}[-]digit.{digit} e sign digit{digit} 
depending on the magnitude of expn. Blanks are added as needed to right justify the string. If format width is too small, the width is increased automatically. See also: erealstr, frealstr, intstr
record keyword
usage:
record 
    item{, item} : type spec 
   {item{, item} : type spec} 
end record 
remarks: Keyword is used to declare a record data type. To access elements of a record type, use the item selector '.' between a variable name and the item identifier.
repeat standard function
usage: repeat(s : string, expn : int) : string
remarks: Function returns expn copies of string s joined together into a single string.
return keyword
usage: return [expn]
remarks: Keyword causes a return from a function or procedure. A function must return a value. The type of expn must be compatible with a function's return type.
round standard function
usage: round(expn : real) : int
remarks: Function returns the integer nearest to expn. See also: ceil, floor
scroll standard procedure
usage:
scroll(top, bottom, left, right, 
       foreground, background, 
       rows_to_scroll : int)
remarks: Procedure scrolls a text mode window where:
top, bottom, left, right : region to scroll 
foreground               : new foreground color 
background               : new background color 
rows_to_scroll           : + up, - down, 0 all 
setexp standard function
usage: setexp(expn : real, exp : int) : real
remarks: Function returns the value of expn with its exponent, base 10, changed to exp. If expn equals 0.0, zero is returned. The value of exp must be within the range shown in the tables in section 10. See also: getexp
setvideo standard procedure
usage: setvideo(expn : int)
remarks: Procedure sets the system's video mode to expn. See section 10 for a table of video mode codes.
sign standard function
usage: sign(expn : real) : int
remarks: Function returns the sign of expn as an integer -1 or +1.
sin standard function
usage: sin(expn : real) : real
remarks: Function returns the sine of expn. The value of expn is assumed to be in units of radians.
sinh standard function
usage: sinh(expn : real) : real
remarks: Function returns the hyperbolic sine of expn. The value ofexpn is assumed to be in units of radians.
sqrt standard function
usage: sqrt(expn : real) : real
remarks: Function returns the square root of expn. The value ofexpn must be non-negative or a run-time error will occur.
string keyword
usage: string[(integer expn)]
remarks: Standard type specifier. The value of integer expn specifies the maximum length of the string which can be no larger than the limit shown in section 10.
strint standard function
usage: strint(s : string) : int
remarks: Function returns the integer equivalent to s. See also: strreal.
strreal standard function
usage: strreal(s : string) : real
remarks: Function returns the real number equivalent of s. See also: strint
succ standard function
usage: succ(expn : int|enum type) : int|enum type
remarks: Function accepts an integer or enumeration value and returns the next value. See also: pred
tan standard function
usage: tan(expn : real) : real
remarks: Function returns the tangent of expn. The value of expn is assumed to be in units of radians.
tanh standard function
usage: tanh(expn : real) : real
remarks: Function returns the hyperbolic tangent of expn. The value of expn is assumed to be in units of radians.
then keyword
usage: if boolean expn then
remarks: See if.
true keyword
usage: name := true
remarks: Boolean constant; opposite of false.
type keyword
usage: type name : type spec
remarks: Declares a named type for the type spec. Normally, type spec is one a user defines using an array, record, union, or enum declaration.
union keyword
usage:
union 
    item{, item} : type spec 
   {item{, item} : type spec} 
end union 
remarks: keyword is used to declare a data type. To access elements of a union type, use the item selector '.' between a variable identifier and the item identifier.
value keyword
usage:
value constant:
value:
remarks: See case.
var keyword
usage: var name{, name} : type spec [:= expn]
remarks: It must precede each variable declaration and is also used to declare that a parameter in a subprogram's parameter list is to be passed by reference.
videomode standard function
usage: videomode : int
remarks: Function returns an integer corresponding to the current video mode. See section 10 for a table of video modes.
videotype standard function
usage: videotype : int
remarks: Function returns an integer corresponding to the system's video display type. See section 10 for a table of video type codes.
watch standard procedure
usage: watch(expn)
remarks: Displays the current value of expn on the debug screen when in debug mode.
when keyword
usage:
exit when boolean expn  
continue when boolean expn
remarks: Used to set a conditional jump in a for or loop statement. See also: for, loop
xor keyword
usage: boolean expn xor boolean expn
remarks: Operator returns a boolean value:
x       y       x xor y
false   false   false
false   true    true
true    false   true
true    true    false


| home | contents | previous | next page | send comment | send link | add bookmark |

Copyright © 2004, Stephen R. Schmitt