There are three steps to be done for each program in order to try and run it. They are edit the program, compile the program, and run the program. In fact, you would have these three steps are any language on any machine.
Editing a program involves typing the program into the computer using a program called an "editor" On our PC's (and most machines nowadays), this involves simply typing the program into the computer. A blank screen is provided for you to type upon. I.E., whenever you press a key, the corresponding letter will appear on the screen.
You then leave the editor, saving the "file."
The next step is converting this file into something that the computer can execute. The computer, or more precisely the "CPU" of the computer, can only execute a specially encoded series of 0's and 1's. To convert our programming language, PASCAL, to this form, we "compile" the programming language. Then we "execute" the program. At this point the program will accept whatever input it's supposed to take and produce the desired output. This is when the functions of the read, write and assignment statement will actually occur.
In order to understand these steps, I must discuss the concept of "file" A file is a collection of characters (or other data) that will remain on the computer forever. Specifically, we can create a file, turn off the computer, come back a week later and then have the same file there, ready to edit, compile or run. We will also see (in unit 1.5), that we can use files to contain data to be input to our program. And our programs can also create and put information into files.
Files are stored on a device called a disk drive. A disk drive uses the same technology as a casette tape or video cassete recorder to ensure that data stays forever. You can think of editing a file as analagous to recording on a tape. And when you compile the program, the computer will "play" the tape for the purpose of generating the executable.
This is unlike the numbers in the "boxes" or "variables" of a program that disappear as soon as the program finishes executing or someone turns off the computer. These are stored in RAM which is faster than a disk, but requires power to the computer to keep the data "alive."
On our machine, a file will have two parts of its name, an eight- character "main name" and a three-character extension. The "main name" is the designator for the program such as "ass_one" or "fillip" or "myprog" or whatever you want to call your program. The extension tells the type of file. Several related files will have the different extension. Often, you can leave out the extension when the application can assume the name.
When we edit a program, we must use the full name. And if it is a PASCAL program we are creating, the extension must be ".PAS" So our editing will be done on "ass_one.pas" or "fillip.pas" or "myprog.pas"
However, when we compile or run the program, we won't need the extension. The PASCAL compiler knows that we are compiling a PASCAL program. It assumes the ".PAS" extension. The compiler produces something with a ".EXE" extension. This is what you run. You simply type its name to run it without the .EXE extension.
One more concept. When you first get to the computer, you will have to login. That way the computer knows who you are. The system will make sure that nobody else looks at your files, or worse, modifies them. You will have to give your account name and your password. Both of these will be handed to you individually on a separate piece of paper. Only you will have this account. You shouldn't let anyone have your password, any more than you would give someone else your charge card or a blank-signed check.
Now that we have all our concepts down, let's look at the steps to execute a program in detail. That is, I will tell you precisely what to type at the computer to run your program.
A. To login into the computer, make sure that you see the
following on the screen:
(CS) F:\LOGIN>
B. Type
LOGIN CS/XXXXXXXX
Press the "ENTER" or carriage return key when finished.
XXXXXXXX is your login id. It will be of the form C20102XX
where XX will be two characters. All the students in my
CS201 class will have a login id beginning C20102. The "XX"
will be different for each of you. It will be something like
"aa" or "bc"
C. The computer will say
Enter your password:
Type your password. Note that as you type, it will not appear
on the screen. This will prevent people from viewing it "over
your shoulder." Then press a carriage return key or ENTER
key.
D. You will get a whole bunch of text on your screen--it might
take fifteen seconds or minute tell everything is done as the
computer "logs you in."
Finally, you receive a prompt that will look like:
(CS) F:\USERS\C20102XX
Except that the XX will be replaced with CC or DA or BF
depending upon what your login id is.
E. You are now ready to "edit" your program.
If this is the first time you are working with this program,
choose a name for your program now. I will refer to this name
as nnnnnnnn
(It is possible, you may want to "edit" an existing program,
perhaps there is some error in it. In that case, you enter
the name you used when you previously referred to the
program.)
Type
TED nnnnnnnn.pas
F. A blank screen will appear, except for the bottom. That line
looks as indicated below.
You now create your program. Simply type your program in from
the piece of paper containing your sample program. It should
look on the screen like the program examples I give you in
your class notes.
You may wish to correct mistakes. You will see four keys with
arrows. On most of the PC's around, there will be four gray
keys on the bottom of the keyboard about 3/4 of the way from
left to right. You can use this to move the cursor around.
This is a blinking underscore character. After you move the
keys, the cursor moves. Then when you type, your text will
appear at the current location of the cursor.
If you want to delete characters, you can press the key marked
"delete" This will be above the arrow keys I mentioned in a
group of six buttons.
(There are many other editing functions available. However,
the above is all you need to earn an A in this class.)
G. You are now ready to "save" your "file" This makes a
permanent record of the file in the disk fo the computer.
This file will last forever and ever--even after you log out
of the computer, they turn them off for the day, and you come
back weeks later!
To do this, press the key marked "F7" It will be on the upper
row of keyboard.
H. You will see a message that says "Save as: nnnn.pas" Press
the carriage return key.
(It is confirming your file name and that you really want to
save the file.)
I. You should now see the message "F:\USERS\C20102XX>" on your
screen.
You are now ready to compile your program.
Type
tp6c nnnnnnnn
(Remember that nnnnnnnn is your program name. Remember also
to leave out the ".PAS" part as this is assumed by the
compiler.)
If your compilation was free of "syntax errors," your output
screen will look as follows:
[[[ Loading Turbo Pascal 6.0 ]]]
Turbo Pascal Version 6.0 Copyright (c) 1983,90 Borland
International
u12.pas(9)
9 lines, 0.1 seconds, 2160 bytes code, 662 bytes data.
If you have syntax errors, you will see a screen like below.
Syntax errors are problems such as mispelled identifier-names,
missing semicolons or commas.
[[[ Loading Turbo Pascal 6.0 ]]]
Turbo Pascal Version 6.0 Copyright (c) 1983,90 Borland
International
TEST.PAS(2): Error 85: ";" expected.
var i:integer;
^(CS) F:\USERS\LEFF>
The caret (^) will tell where Turbo PASCAL compiler was when
it detected the error. Sometimes this will be somehat after
the actual mistake you made. In particular, if you leave out
the semicolon from a line, the error will come out on the
following line.
You will have to go back to step E to remedy the problem.
J. Type
nnnnnnnn
to run your program. Note that you will not need any
extension--just the name of the program. The program will sit
there awaiting any input that your program might need from a
read statement. After Unit 1.4, you will be able to print out
nice prompts so the user will know what the program is waiting
for.
K. If you don't have the right output, go to step E to fix
problem.
L. If you would like to print the PASCAL program on the LASER
printer,
type the following command
PRINT nnnnnnnn.PAS
You may get a query:
Name of list device[PRN]:
If so, simply press the carriage return key.
M. If you are finished, type
LOGOUT
and press the carriage return key.
This ensures that noone else can destroy your files.
Also, should you leave the computer logged in to your account,
it ,ogjt confuse a student trying to use the computer after
you. This would be likely if that student was from CS101 and
other courses where individual accounts weren't used.