Predefined Functions
The following standard primitive functions are available at runtime in Tiger.
Note
Some runtime function may fail if some assertions are not fulfilled.
In that case, the program must exit with a properly labeled error message,
and with exit code 120
. The error messages must follow the standard.
Any difference, in better or worse, is a failure to comply with this
Tiger Reference Manual.
- string: chr (code: int)
- Return the one character long string containing the character which code is
code
.Ifcode
does not belong to the range [0..255], raise a runtime error:chr: character out of range
. - string: concat (first: string, second: string)
Concatenate
first
andsecond
.- void: exit (status: int)
Exit the program with exit code
status
.- void: flush ()
Flush the output buffer.
- string: getchar ()
Read a character on input. Return an empty string on an end of file.
- int: not (boolean: int)
Return 1 if
boolean
= 0, else return 0.- int: ord (string: string)
Return the ASCII code of the first character in
string
and -1 if the given string is empty.- void: print (string: string)
Print
string
on the standard output.- void: print_err (string: string)
Note: this is an EPITA extension. Same as
print
, but the output is written to the standard error.- void: print_int (int: int)
Note: this is an EPITA extension. Output
int
in its decimal canonical form (equivalent to%d
forprintf
).- int: size (string: string)
Return the size in characters of the
string
.- int: strcmp (a: string, b: string)
Note: this is an EPITA extension. Compare the strings
a
andb
. Return -1 ifa
<b
, 0 if equal, and 1 otherwise.- int: streq (a: string, b: string)
Note: this is an EPITA extension. Return 1 if the strings
a
andb
are equal, 0 otherwise. Often faster than strcmp to test string equality.- string: substring (string: string, first: int, length: int)
Return a string composed of the characters of
string
starting at thefirst
character (0 being the origin), and composed oflength
characters (i.e., up to and including the characterfirst
+length
- 1).Let
size
be the size of thestring
, the following assertions must hold:0 <=
first
0 <=
length
first
+length
<=size
Otherwise a runtime failure is raised:
substring: arguments out of bounds
.