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

1. Getting started

This chapter explains how to setup your computer so that you can use the T interpreter. It also explains how to use the three programs which make up the programming environment. Lastly, there is an example which shows how to enter and run a T program which you should try.

installing the T interpreter

Here it is assumed that your computer's hard disk drive is the c: drive, its floppy disk drive is the a: drive, and that you are copying the T interpreter files from a distribution diskette.

First, log on to the root directory and create a new directory for these programs:

C:\>md tpl                press the Enter key
Second, insert the diskette containing the T Interpreter into the a: drive and check that you received all the needed files:
C:\>a:                    press Enter
A:\>dir                   press Enter
You should see listed:
TI.EXE                    the interpreter
TH.EXE                    the language help program
TE.EXE                    the editor
and several files which have the file name extension .T indicating that they are T programs. These are provided as samples.

Third, copy all these files to the new directory you just created:

A:\>copy *.* c:\tpl  press Enter
That's all you need to do!

writing a T program

Every T program is a sequence of declarations and statements that begins and ends within a program block. The following is a complete T program:

program
    put "Hello!"
end program
A T program is made up of key words, literal constants, special symbols, and standard subprograms. In the example above, put is a key word, " is a special symbol, and "Hello!" is a literal constant string.

The usual form of a T program is modular. The program module defines both the start and end of a program. All executable statements are contained within this module or within procedure or function (subprogram) modules. Global variable declarations and data type definitions must be located outside of the program and any subprogram modules.

running a T program

This is an example of a simple T program:

% the first program

const x := 2
const y := 4

program

    var sum : int

    sum := x + y
    put x, " +", y, " =", sum

end program
Enter this program, and run it using the instructions which follow. The first step is to start the editor (change to the T directory if necessary):
C:\TPL>te 	          press Enter
You should see the following on your video display:
  1:1                        UN_NAMED.T                              F10 Help   
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
Note that F10 Help appears in the upper right of the screen, this means that the F10 function key is used to call a pop-up menu of built-in help information which you may need. Try pressing the F10 key on the top row of your keyboard to see what happens.

You should see:

  1:1                        UN_NAMED.T                              F10 Help   
                                                                                
                                                                                
                                                                                
                               --- help ----                                    
                              |             |                                   
                              |  Language   |                                   
                              |  Keyboard   |                                   
                              |  Ctrl + K   |                                   
                              |  Fx keys    |                                   
                              |  About      |                                   
                              |             |                                   
                               -------------                                    
                                                                                
                                                                                
                                                                                
The up and down arrow keys on your keyboard can be used to select an item from the menu. The help item highlighted in white is the item selected. To activate it, press the Enter key. Try out all the help items. To exit from the menu, just press the Esc key which is usually placed at the upper left corner of your keyboard.

Now select the item named Keyboard. This one explains how the keyboard is used as a typewriter to enter text into a file. Study it before you begin to enter the sample program above.

Enter the sample program into the computer. After you have finished, press the F1 key. On the pop-up menu select Write to. Type a name for your program; how about first.t? Note the .t; this is the file name extension used by the editor to identify T programs. Press Enter when you've finished. At the top of the edit screen, the UN_NAMED.T should disappear and be replaced with the name you typed.

Now press the F3 key and select Debugger on the pop-up window. When you press enter, the editor will save your file and start the interpreter in its debugging mode using your file as source code. If you entered correct code you should see your file with a gray bar highlighting the first executable line.

If you entered incorrect code you will see an error message. If this happened, press F3 again and select Errors and press Enter. The editor will show you where the errors are. Each line containing an error will be highlighted and the cursor will point to the error. Sometimes the editor will point to the symbol or word just after the error. The bottom line of the screen will contain a short message describing the error. Press any key to step to the next error. Press the Esc key to stop at the current error. You can resume from the start by selecting Errors again.

Let's assume that either you entered the program correctly or you corrected any errors and started the interpreter again in the debugging mode. Press the spacebar. The highlight will jump to the next line containing a statement. Keep doing this until the interpreter gives you a "Success" message. Each line containing an executable statement was highlighted. The debugging mode of the interpreter has more features which are easy to use. Try starting the debug mode again as we did above. Press F10 again. The pop-up window shows the all the debugging options and the corresponding function keys. You should try them out to see how they work.

debugging

The T interpreter includes features to make it easier for you to debug your programs.

The assert statement has the form:

assert boolean expression
If the boolean expression is false during program execution the program is halted. This example would terminate a program because of invalid data:
get x              % from console
assert x > 0.0     % if false, halt
put sqrt( x )      % do if true
The watch procedure allows you to observe variables while debugging a program. It is written as a statement in a program with the form:
watch(expression)
When the interpreter is in the debug mode, the value of the expression is displayed at the bottom of the debug screen. Try this out in the first.t program.

include files

The interpreter has a feature which allows you to combine several small files into a larger program. The statement:

include filename
can be inserted anywhere in a file. When the interpreter reads this statement, filename is opened and read into the interpreter as if its text was located at that point.

comments and white space

Above there are some lines containing the character % indicating that all following text to the end of the line is a comment and not part of the program. Comments, together with white space (spaces between symbols and blank lines) make a program easier to read and understand. This is important if you want to show your program to someone else or use it again yourself at some future time. T is a free form language. As long as the words and symbols are in the correct order, a program will run correctly. It is up to you to make a program easy to read and understand. It is often helpful to add comments and name identifiers in such a way that each step of the debugger is easily understood.

command line options

The T interpreter programs can be run directly from the DOS prompt. Try the following:

C:\TPL>te first.t         press Enter
The editor should start up and immediately load "first.t" if it is in the directory. Now quit the editor and try the following:
C:\TPL>ti first.t debug   press Enter
The interpreter should run in debug mode. Now try:
C:\TPL>ti first.t         press Enter
The program should run. If the code has errors, a message will be displayed. You can load the source file into the editor and select Errors to examine them. Note that a program can be halted by pressing the Esc key.

The language reference program can be run from the DOS command line as well as from the editor. Try:

C:\TPL>th                 press Enter
Use the arrow keys to select a menu item then press Enter. Pressing any key returns to the language menu. Pressing Esc quits the language help program.

conventions used in this manual

In the first.t program, the words program, const, var, int, put, and end were in bold type. These are some of T's key words. In this manual, key words will be shown in bold type so they will not be confused with T's standard procedures and functions or with names of data such as x, y, and sum which you, the programmer, define.

Italic letters are will be used to describe items and where they belong in your programs. Square brackets, [item], mean that the item is optional. Braces, {item}, mean that the item is optional and can be repeated.

summary

This chapter explained how to use the T interpreter and showed how to put together a T program. Several sample programs have been included with the T interpreter software for your use in learning the T programming language. You should study all the pop-up windows to see how the interpreter and editor work. Section 11 contains a summary of all of the editor and debugger commands.


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

Copyright © 2004, Stephen R. Schmitt