Syntax
The syntax of all versions of TI-BASIC are somewhat different from typical BASIC implementations. The language itself has some basic:=
operator, TI-BASIC uses a right-arrow sto''→''
operator with the syntax: ''source → destination''. This is similar to several Japanese calculators, such as from Casio, Canon and Sharp, that have often employed a similar syntax, ever since the first mass market Japanese alphanumerical calculators appeared in the late 1970s and early 1980s.
Control flow
If condition Then ... Else ... End For(variable,start,stop,step) ... End While condition ... End Repeat condition ... EndUnusual for a high level language, TI-BASIC implementations include IS> (Increment and Skip if Greater Than) and DS< (Decrement and Skip if Less Than) statements, constructs generally associated with
Menu(
functions rather than as program or block labels.
Availability of functions and subroutines depends on the implementation; the versions available on the TI-82-descended calculators do not even support a Data types
TI-BASIC is a strongly andTI-83/84 (Z80)
* Numerical variables, includingA
- Z
and θ
(theta). These allow Str0
- Str9
. These may store any number of characters or even function names, as long as there is available memory. They can be evaluated as an expression with the expr()
function, which is found in the catalog.
* Lists, including L1
- L6
, with the ability to create additional ones. These are essentially dim(
of the list name. The default lists are named L1–L6, but custom lists can be created. This is done by setting dimension of a list referenced with the L token in the Lists
, followed by a name ranging from 1 to 5 A
- Z
and θ
. Individual elements of lists can be accessed by placing the element number in /code> - /code>. Their elements are subject to the same restrictions as lists. Their dimensions may be defined up to 99x99 elements, although, again, available memory will limit this. It is not possible to create user-defined matrices, so only the ten built in ones may be utilized.
* Equation variables, including Y0
- Y9
, r1
- r6
, and u
, v
, w
. These are essentially strings which store equations. They are evaluated to return a value when used in an expression or program. Specific values, (constant, C) can be plugged in for the independent variable (X) by following the equation name (dependent, Y) by the constant value in parentheses. In the example below, "(4)" is used (for no particular reason). (Y1
(4) would return the value of Y1
at X=4)
Data types that cannot be directly manipulated include:
* Pictures (Pic0
- Pic9
)
* Background (Image0
- Image9
)
* Programs (prgm
)
* Graph databases (GDB0
- GDB9
)
* Color (BLUE
, RED
,..., GRAY
) (15 colors in total)
TI-89 (68k)
* Integers, which can store a large amount of data. The 68k calculators can store very large numbers, as high as , with perfect accuracy.
* Real numbers, using decimal floating point
Decimal floating-point (DFP) arithmetic refers to both a representation and operations on decimal floating-point numbers. Working directly with decimal (base-10) fractions can avoid the rounding errors that otherwise typically occur when convert ...
. These store up to 14 significant digits depending on the calculator model.
* Complex numbers
In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the form a ...
, implemented as pairs of reals.
* Strings
String or strings may refer to:
*String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects
Arts, entertainment, and media Films
* ''Strings'' (1991 film), a Canadian anim ...
* Lists, which are one-dimensional linked list
In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes whic ...
s which support element-wise operations. On the 68k calculators, elements can be integers, reals, complex numbers, strings or expressions.
* Matrices
Matrix most commonly refers to:
* ''The Matrix'' (franchise), an American media franchise
** ''The Matrix'', a 1999 science-fiction action film
** "The Matrix", a fictional setting, a virtual reality environment, within ''The Matrix'' (franchis ...
, with elements subject to the same restrictions in lists
* Symbolic expressions, unique to the 68k series.
Data types that cannot be directly manipulated (typing only their name on a line would result in an error) include:
* Pictures
* Data
* Programs
* Functions
Variables
Flexibility in the use of variables varies widely by the calculator model. For example, on the TI-84 Plus
The TI-84 Plus is a graphing calculator made by Texas Instruments which was released in early 2004. There is no original TI-84, only the TI-84 Plus, the TI-84 Plus Silver Edition models, and the TI-84 Plus CE. The TI-84 Plus is an enhanced ve ...
, all English language letters as well as theta (Θ) are available.
TI-83/84 (Z80)
On the TI-83/84, the programmer can create lists whose names are up to five characters. All other data types are limited, such as the 27 real or complex variables, and a number of predefined variable names of other types (e.g., matrices have to be one of the ten variables /code>- /code>). On the TI-83/84 certain variables such as Ans
and the finance variables have fixed addresses in RAM, making them much faster to access than the 27 letter variables. Ans
acts as a special variable containing the result of the last evaluated code. A line with just a variable will still be evaluated and its contents stored in Ans
as a result. Because Ans
is reevaluated so frequently it most often is used to store very temporary calculations or to hold values that would otherwise be slow to access such as items from a list. All variables are global.
TI-89 (68k)
In contrast, 68k calculators allow all variable names to have up to eight alphanumeric characters, including Greek
Greek may refer to:
Greece
Anything of, from, or related to Greece, a country in Southern Europe:
*Greeks, an ethnic group.
*Greek language, a branch of the Indo-European language family.
**Proto-Greek language, the assumed last common ancestor ...
. Furthermore, variables can be grouped into "folders", or made local
Local may refer to:
Geography and transportation
* Local (train), a train serving local traffic demand
* Local, Missouri, a community in the United States
* Local government, a form of public administration, usually the lowest tier of administrat ...
to a program by declaring them with the Local
statement.
Comments
TI-83/84 (Z80)
Z80 programmers often start lines with " (double quotation mark) to denote a comment. Lines starting with " are actually executed changing the Ans
variable, but this does not affect anything other than performance unless Ans
is read immediately afterwards.
TI-89 (68k)
The 68k calculators allow programs to include single-line comments, using © as a comment symbol. If a comment appears as the first line after the "Prgm" statement, it is displayed in the status bar when the program is selected in the catalog; such comments are often used to document the names or types of parameters. The 68k interpreter has a built in feature to store the number of space characters at the beginning of a line, this allows indentation
__FORCETOC__
In the written form of many languages, an indentation or indent is an empty space at the beginning of a line to signal the start of a new paragraph. Many computer languages have adopted this technique to designate "paragraphs" or o ...
.
Functions
TI-83/84 (Z80)
The Z80 version of TI-BASIC makes explicit "functions" like those in 68k impossible. However, all variables are global so functions can be emulated by setting variables, similar to arguments, before calling another program. Return values do not exist; the Return
statement stops the current program and continues where the program was called.
TI-89 (68k)
The 68k version of TI-BASIC allows creating user-defined functions. Functions have the same syntax as programs except that they use the Func
...EndFunc
keywords instead of Prgm
...EndPrgm
, and that they are not allowed to use instructions that perform I/O, modify non-local variables, nor call programs. However, functions can still be non-pure
Pure may refer to:
Computing
* A pure function
* A pure virtual function
* PureSystems, a family of computer systems introduced by IBM in 2012
* Pure Software, a company founded in 1991 by Reed Hastings to support the Purify tool
* Pure-FTPd, F ...
because they can call built-in functions such as getTime()
, getKey()
, or rand()
. All functions have a return value, which in the absence of an explicit Return
statement is the last expression evaluated.
Third-party language extensions
Third-party applications, in chronological order Omnicalc, xLIB, Celtic, and Doors CS, have overloaded TI-BASIC functions on the Z80 calculators to provide additional language functionality. The third-party libraries overload the sum()
, real()
, det()
and identity()
functions, which are handled and interpreted by their respective applications. Among the extra functions are fast shape-drawing routines, sprite and tilemap tools, program and VAT modification and access abilities, GUI construction features, and much more, most of which are ordinarily restricted to use by assembly programmers. All of the functions require that an application lik
Doors CS 7.0
be present on the user's calculator, sometimes considered a detraction to the use of the libraries.
Examples
Hello world
The following programs, when executed, will display the phrase " HELLO, WORLD!
".
TI-83/84 (Z80 Series)
:Disp "HELLO, WORLD!"
TI-89 (68k Series)
(P.S. this code can be shortened down to just the Disp function, like in the TI-83/84, and the hellowld, prgm, and endprgm are auto-generated.)
:hellowld()
:Prgm
:ClrIO
:Disp "HELLO, WORLD!"
:Pause
:ClrIO
:DispHome
:EndPrgm
TI-Nspire
text "HELLO, WORLD!"
TI-Nspire CX
text "HELLO, WORLD!"
Lists and loops
TI-83/84 (Z80 Series)
PROGRAM:LISTS
:"ASK FOR THE NUMBER OF VARIABLES
:Input "NUMBER OF VARS? ",A
:"VALIDATE INPUT OR STOP
:If A<1 or fPart(A)
:Stop
:"A FOR LOOP TO ASK FOR EACH VALUE TO BE IN THE LIST
:For(N,1,A
:Input "VAR ",B
:"STORE THE VALUE INTO THE NTH ELEMENT
:B→L1(N)
:End
:"IMPLICITLY RETURN THE FINAL LIST
:L1
TI-89 (68k Series)
lists()
:Prgm
: Local n,i,c © Declare local variables n, i, and c.
: →list © Initialize list as an empty list.
: Input "Number of variables?",n
: For i,1,n
: Input "Variable #"&string(i),c © & concatenates i after it is converted to a string.
: c→list : EndFor
:EndPrgm
Lists have many possible names, this allows for many programs to manipulate many lists without overriding previous data. Lists on the TI-82 cannot have custom names (L1 through L6 are preprogrammed). The TI-85 and TI-86 do not have the ability to handle a variable name with subscripts. The TI-81 is completely unable to handle lists. Lists can be used by the numerous built-in TI-BASIC functions for calculating statistics, including various regression analyses an
more
These can be called inside of programs, however they still show the info while pausing execution and they cannot store specific results into variables.
Recursion
Recursion is possible. A program can be called from within itself or from within another program.
TI-83/84 (Z80 Series)
The example below is used to compute factorial
In mathematics, the factorial of a non-negative denoted is the product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial:
\begin
n! &= n \times (n-1) \times (n-2) \t ...
s. In order for it to work, X
is the parameter of the factorial function and A
must equal 1.
PROGRAM:FACT
:If X=0
:Then
:Disp A
:Stop
:End
:XA→A
:X-1→X
:prgmFACT
TI-89 (68k Series)
factui()
:Prgm
: Local n
: Define fact(x)=Func
: If x=0
: Return 1
: Return x*fact(x-1)
: EndFunc
: Input "Input a number", n
: Disp "n! = "
: Disp fact(n)
:EndPrgm
Functions
The 68k series makes a distinction between programs and functions. Functions are just like programs except that they do not allow statements that perform I/O, including modifying non-local variables, and they return a value, which in the absence of an explicit Return
statement is the last expression evaluated.
fact(x)
:Func
: If x=0
: Return 1
: If x<0
: Return undef
: x*fact(x-1)
:End Func
Editors and Tools
The growth of the hobbyist graphing calculator community in the 1990s brought with it sharing and collaboration, including the need to share TI-BASIC code on mailing lists and discussion forums. At first, this was done by typing out the TI-BASIC code from a calculator screen into a computer by hand, or conversely, entering programs manually into calculators. TI-BASIC programs are stored in a tokenized
In computer science, lexical analysis, lexing or tokenization is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of ''lexical tokens'' ( strings with an assigned and thus identified ...
format, they cannot be edited using standard computer text editors, so as the calculator programming community matured, a need for an automated converter arose. The format for computer-stored TI-BASIC programs generated by Texas Instruments' TI-GraphLink application was eventually decoded, and third-party tools were created to manipulate these files. TI created a BASIC editor that they included in certain releases of the TI-GraphLink linking program, but it has not gained widespread usage. In particular, it used a custom character set that did not display properly when copied and pasted to fora.
In 2005, Joe Penna created OptiBASIC, a translator tool to convert text from the TI-GraphLink editor into standard Unicode. The project soon expanded to include a regex-based TI-BASIC optimizer. Independently, Christopher "Kerm Martian" Mitchell of Cemetech
Cemetech is a programming and hardware development group and developer community founded in 2000. Its primary software focus is calculator programming for TI and Casio graphing calculators, and its primary hardware focus is on mobile and wearab ...
began creating an online converter to extract plain-text (and later HTML and BBCode
BBCode ("Bulletin Board Code") is a lightweight markup language used to format messages in much Internet forum software, first introduced in 1998. The available "tags" of BBCode are usually indicated by square brackets ( _and_.html" ;"title="/code> ...
-formatted) contents from tokenized TI-BASIC programs, which expanded to include an online program editor, exporter, and TI-83 Plus emulator. The SourceCoder project absorbed OptiBASIC at the end of 2005. The only other major TI-BASIC editor currently in use is TokenIDE (or "Tokens"), created by Shaun "Merthsoft" McFall. An offline editor, Tokens can import, edit, and export TI-BASIC programs, includes tools to track program size and correctness, and offers ancillary features such as a sprite/image editor. Built around token definitions stored in XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
files, it is intended to be extensible to work with any user-specified token mapping.
Programmes on the NSprire series as well as TI 92 plus and Voyage 200 calculators can be transferred and saved in flat clear text (Ansi/Ascii/ISO 8859-*) format and there are several IDEs for TI calculator programming. A series of TextPad
TextPad is a text editor for Microsoft Windows developed by Helios Software Solutions. It is currently in its eighth major version. TextPad was initially released in 1992 as shareware, with users requested to pay a registration fee to support ...
syntax definitions, code snippets, and charts are available for the TI calculators, and the syntax definitions have also been converted to the format used by the Zeus editor.Programming - ticalc.org The clear text format is also used for the Lua interpreter on the calculator.
An independent project exists for developing a PC-side interpreter for the TI89-92-Voyage 200 variant of TI Basic that would allow programmes for the calculator to be run directly"Calculator Programming Today", The Spreadsheet Vol VI, No 14, 23. November 2004 pp 5 as well as combined programmes of other languages which call this interpreter. The interpreter uses standard input, output, error and specifiable log and configuration files in console mode under Windows, and a second programme to replicate the graphics used on the calculator would be related to it in the same way as the Tk tools which are integrated with Tcl
TCL or Tcl or TCLs may refer to:
Business
* TCL Technology, a Chinese consumer electronics and appliance company
**TCL Electronics, a subsidiary of TCL Technology
* Texas Collegiate League, a collegiate baseball league
* Trade Centre Limited ...
, Perl
Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
, Rexx
Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
, C and other languages. A related project for developing a Tk kind of tool for use by VBScript is the source of this tool. A third tool which integrates the PC-side TI Basic with spreadsheet and database programmes via VBA and WSH engines is also envisioned. This project also involves a calculator-side Unix-style shell and Rexx and Perl interpreters, a Fortran 77 interpreter, as well as converters to go back and forth amongst the various Casio, HP, Sharp, and Texas Instruments calculator programming languages and to and from those and various scripting languages
A scripting language or script language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. Scripting languages are usually interpreted at runtime rather than compiled.
A scripting ...
.
See also
* Calculator gaming
* Programmable calculator
Programmable calculators are calculators that can automatically carry out a sequence of operations under control of a stored computer programming, program. Most are Turing complete, and, as such, are theoretically general-purpose computers. Howe ...
* Casio BASIC
Casio BASIC is a programming language used in the Casio calculators such as the Classpad, PRIZM Series, fx-9860G Series, fx-5800P, Algebra FX and CFX graphing calculators.
This programming language has nothing to do with the more or less standa ...
* RPL (programming language)
RPL is a handheld calculator operating system and application programming language used on Hewlett-Packard's scientific graphing RPN (Reverse Polish Notation) calculators of the HP 28, 48, 49 and 50 series, but it is also usable on non-RPN c ...
References
External links
Texas Instruments' official website
{{BASIC
Texas Instruments calculators
Articles with example BASIC code
Graphing calculator software
BASIC interpreters
BASIC programming language family