Category : Pascal Source Code
Archive   : ALICE.ZIP
Filename : ALICE.DOC

Output of file : ALICE.DOC contained in archive : ALICE.ZIP

ALICE -1- The Personal Pascal

1. Introduction

This file contains excerpts from the ALICE documentation. To get
a general idea of what ALICE does, we suggest you first run the demons-
tration session according to the instructions on your demo disk. This
document is mostly Chapter 3 of our Tutorial guide. As such, it assumes
you have gone through the introduction in Chapter 2. This first session
is very similar to the start of the demonstration session, so you should
be able to work from that background.

For full documentation, you should refer to the tutorial guide,
user's manual and full teaching textbook that are available with the
complete version of ALICE. If you're an experienced programmer, these
manuals will be important because they contain not just information on
using Alice, but technical details, including information on customizing
Alice to make it easy and fast to use for more sophisticated program-

ALICE: The Personal Pascal is a total computing environment that
makes programming faster and easier. It is particulary useful for peo-
ple learning programming, for example in high school, college or univer-
sity, but it can also be of great help to more experienced programmers.

The heart of ALICE is a "program editor". Unlike a normal text
editor, the ALICE program editor is intimately linked to a specific
programming language. The editor knows the syntax of the language and
makes it virtually impossible for the user to enter a syntax error. At
every stage in the programming process, users have a syntactically
correct program. This is particularly helpful for beginning programmers
-- instead of worrying about trivialities like unbalanced parentheses,
novice programmers are freed to concentrate on what is truly important:
program logic. The ALICE program editor can also detect a number of se-
mantic errors, e.g. undeclared variables, invalid operations, and so on.

The ALICE environment also includes an interpreter and debugger for
the programming language. The interpreter can run more quickly than
other interpreters, because the program editor automatically parses user
input as the program is being entered. Internally, the program is
stored in a tree structure that makes the interpreter's job very easy.

The debugger is linked to the interpreter and the editor, and can
make use of their facilities. As an example, ALICE allows the user to
"single-step" through a program, executing one instruction at a time.
In between instructions, users can perform a large number of operations,
such as printing out or changing the values of variables. This can
speed the debugging process immensely, because it allows users to "get
inside" their programs as the programs run.

As another example of the interplay between debugger, interpreter,
and editor, ALICE supports "cursor-following". While the program is
executing, the source code is displayed on the screen and the cursor

ALICE -2- The Personal Pascal

moves through the code showing the instructions that are being executed.
This allows the user to "see" the program in action. Not only is this
an excellent tool for visualizing program logic, but it can also aid in
locating problems in the program's code.

One of the most important aspects of ALICE is the on-line HELP
facility, providing help and information on all aspects of ALICE and the
programming language. HELP will also explain errors in full detail, and
provide introductory lessons on the use of ALICE.

A unique feature of the HELP system is the "What can I type
here?" menu. This is a menu of all the inputs that are legal at a
particular point in the program. If the user is about to enter a state-
ment, ALICE lists the various kinds of statements that are supported by
the language. If the user is about to enter a variable, ALICE lists all
the variables that are currently defined at this point in the program.
If the user is about to enter a subroutine call, ALICE lists all the
subroutines that could legally be called.

Users can either type in one of the possibilities named in the
menu, or they can select one of the items using a standard menu selec-
tion technique and have ALICE fill in what is desired. In this way,
users can do most of their programming by menu if they want to.

Menus are an important part of the ALICE user interface. Programs
may be written from menus; HELP is chosen from a Help Menu; and all
ALICE commands may be executed from menus. ALICE commands may also be
"bound" to keys, so the commands can be executed simply by typing the
appropriate key. ALICE comes with a set of default bindings, but users
can set up their own bindings if they prefer. Indeed, users can bind
any character sequence to any key, making common operations extremely
easy to enter.

All these factors combine to make ALICE a unique programming and
educational tool. The word "unique" is important. Some program editors
were developed before ALICE, but most of these were prototypes
constructed at universities (notably Cornell). We know of no product on
the market that offers the comprehensive facilities available through
ALICE. However, it is only a matter of time before ALICE and software
like it make their impact on the programming world. By offering an
entirely new approach to the preparation of programs, ALICE gives users
the chance to concentrate on the "important" aspects of programming and
to avoid most of the mundane stumbling blocks that often loom so large.

ALICE -3- The Personal Pascal

1.1. For Experienced Users

At the end of this file, you'll find a brief description of the
important features of ALICE to get you going if you're an experienced

2. First Session

If you have run the demonstration, you should already have an idea
of how to enter and run a simple program with ALICE. You may want to go
through this by hand using the same keystrokes you saw in the demonstra-
tion, just to get a feel for these operations. Also, if you note on the
Starting Menu (that appears when you first run the ALICE program), you
will find several selections that can help you use ALICE. The most
important is "What is ALICE all about?".

Remember about UNDO (CTRL-U) at all times. It will save you if you
make a mistake. Also remember that you can quit ALICE at any time by
pressing F8 and selecting "Quit ALICE".

3. Exploring ALICE

In this chapter, we'll walk through some more simple editing
operations using ALICE. Again, you should follow along on the computer
as you read so you can actually see ALICE in action.

3.1. Loading Saved Programs

Last chapter, we saved our sample program in a file we called
"squares.ap". We'll be doing more with this program, so the first thing
to do is to get the program back from the file. This process is called

Start up ALICE in the usual way. This time, choose the selection

Load in an existing Pascal Program

from the Starting Menu. Remember, to choose something from a menu,
press the letter that labels the selection or press the up or down arrow
key until the selection you want is highlighted, and then press the
space bar. Do this now.

ALICE will respond by giving you a menu of files and directories,
just as it did when you wanted to save your program. This time, though,

ALICE -4- The Personal Pascal

you should see your file "squares.ap" listed on this menu. ALICE knows
that this file contains an ALICE Pascal program because of the ".ap" on
the end.

Choose the "squares.ap" file name from the list in the usual way.
ALICE will load the program from the file and display the source code on
the terminal screen.

By the way, the program you are loading "must" be one that was
previously saved by ALICE. We've mentioned before that ALICE always
uses a special internal format to store programs. If the program wasn't
saved in this format, ALICE won't be able to load it successfully and
will give you a message saying so.

Now that you've loaded the program, you can run it or single step
through it again if you like. To run it normally, press F1; to single
step, press F2. Do this just to remind yourself how ALICE works.

3.2. Moving The Cursor

Many of the things that we will do with ALICE in the rest of the
chapter depend on the position of the cursor. Because of this, we're
going to spend some time describing different ways to move the cursor
around your program.

So far, we have been using the arrow keys and TAB to move the cur-
sor around on the screen. This is a simple process, but there are other
keys that may also be useful.

When you are moving the cursor "around your program" there are
several special keys that you'll find useful. We stress that these are
only for moving the cursor through your program; you should not use them
for moving the cursor when you are selecting something from a menu.

As you have seen, the TAB key jumps to the next "changeable" thing
in your program. For example, move the cursor to the start of the for
statement in your squares program, i.e. the keyword for in

for i := 1 to 10 do begin

If you press TAB once, you will move to the "i", because the "i" could
be changed to a different variable name. If you press TAB again, the
cursor will jump to the number "1". It skips over the ":=" because that
can't be changed; it always has to be there in the for statement. Keep
pressing TAB and the cursor will keep jumping forward. It skips over
the to (which can be changed to downto but only in a special way), over
the do begin and over the end. These are skipped because they are part
of the standard for statement template and cannot be changed.

ALICE -5- The Personal Pascal

When you get to the last statement of the program and press TAB,
nothing happens. You're at the end, so you can't go forward any more.
Are you stuck there? Not at all. You can go backwards by using the
usual arrow keys. You can go to the very top of your program by press-
ing the HOME key. Or, you can hold the SHIFT key and press TAB.

Press SHIFT-TAB and see what happens. The cursor moves backwards.
SHIFT-TAB is the reverse of TAB. Pressing it over and over will move
backwards through all the user-entered things in your program. Try it.

The ENTER key is like the carriage return on a typewriter. When
you press it, ALICE moves the cursor down to the next line. However,
ALICE does a little more as well. Move the cursor to the begin line of
your program (before the for loop) and press ENTER. You will see that
ALICE creates a new Statement placeholder before the for loop. If you
press ENTER again, ALICE will stay on the Statement placeholder it has
just made. Move the cursor to the keyword for and press ENTER. This
time, you will get an empty Statement placeholder inside the for loop.

The general rule is this: if the cursor is not on a placeholder,
pressing ENTER will move to the next line and create an appropriate
placeholder there (if there isn't one there already). If you are in a
declaration section, this new placeholder will be a declaration place-
holder; if you are in the executable part of your program, it will be a
Statement placeholder. If the cursor is already on a placeholder of the
appropriate type, pressing ENTER does nothing. Thus, ENTER always gives
you a new placeholder.

Try this and see how it works. Leave a few empty placeholders ly-
ing around for what we're going to do in the next paragraph.

The characters "CTRL-rightarrow" and "CTRL-leftarrow" are something
like TAB and SHIFT-TAB, in that they jump through the program. "CTRL-
rightarrow" will jump "forward" to the nearest empty placeholder in the
program, while "CTRL-leftarrow" will jump "backward" to the nearest
empty placeholder. Use ENTER to create a few empty placeholders in your
program if you haven't already, then try out "CTRL-leftarrow" and "CTRL-
rightarrow" to see how they work. What happens when you get to the end
of the program and push "CTRL-rightarrow"? Try it and see.

We should also point out that "CTRL-leftarrow" and "CTRL-
rightarrow" will jump to parts of your program that have been highlight-
ed because they contain errors. (Remember how the variable name "junk"
was highlighted in our work last chapter because the variable hadn't
been declared.) Error-highlighted things are almost the same as empty
placeholders; they aren't correct Pascal, so ALICE behaves as if they
still have to be filled in with something.

ALICE -6- The Personal Pascal

3.3. Adding Things to a Program

In the next few sections, we're going to cover a few basic editing
operations: adding things to a program, deleting things from the
program, and changing things that are already there.

We'll start with adding things. The most common things to add are
probably statements and declarations. To add a statement, you need to
make a Statement placeholder in the position where you want the state-
ment to go. You should have the old sample program on your screen now.

program squares (input,output);
{This program prints out the first ten squares.}
i : integer; {A counter}
for i := 1 to 10 do begin

Let's add a "writeln" instruction before the for loop so we can print
out a heading before the list of numbers. The easiest way to do this is
to move the cursor to the word begin before the for statement and press
ENTER. As you've seen before, the cursor will jump down a line and
create an empty Statement placeholder. You can now fill this with a
"writeln" instruction like

writeln('This is a table of numbers and squares.');

You learned how to enter a "writeln" instruction in the last chapter.
When you have entered the instruction, run the program to see how it

Now move to the declaration for "i" in the declaration section and
press ENTER. The cursor will move down a line, and this time create an
empty Variable-Declaration placeholder. Just for the sake of interest,
let's fill in a declaration for a character variable here.

c : char; {A character}

By now, you should know how to fill all this in. You've already filled
in this sort of thing when you set up the declaration for "i".

Now you know how to add Statement and Declaration placeholders to
your program. What about adding other things? For example, we have the

i : integer; {A counter}

ALICE -7- The Personal Pascal

How can we change this to something like

j, i : integer; {A counter}

In other words, how do you add another variable name to a declaration?

The first step is to add a placeholder to the declaration. Move
the cursor to the "i" in the declaration and press INS. This stands for
"insert". You should see ALICE display this.

Name, i : integer; {A counter}

Pressing INS has inserted the placeholder you want. You can now fill
this in with a "j" to get

j, i : integer; {A counter}

Now there's a trick here. ALICE has to guess what kind of place-
holder you want inserted. The placeholder it chooses is always the
smallest that makes sense.

To understand what we're talking about, move the cursor to the word
"integer" in the declaration we've been working with and press INS
again. ALICE sees that you are pointing to a data type and asks if it
makes sense to add another Type placeholder here. Of course, it
doesn't, because

name : type, type;

is illegal in Pascal. The smallest thing that ALICE can insert is an
entire Variable-Declaration placeholder. You'll see that this is exact-
ly what happens when you press INS.

i : integer; {A counter}

Let's try this somewhere else. Move down to the instruction


Put the cursor on top of the first argument "i" and press INS. You'll
see that you get


Why? Because you were pointing to "i" which filled in a Value place-
holder, so ALICE could insert the same sort of placeholder. What
happens if you move the cursor to the word "writeln" and press INS?

ALICE -8- The Personal Pascal

You'll get a new Statement placeholder in front of the "writeln". You
get the smallest kind of placeholder that can be inserted here. Just to
make sure you know what's happening, move the cursor to the "i*i" and
press INS again. You'll insert a Value placeholder. Make sure you
understand why.

You will probably want to experiment a little with inserting new
placeholders here and there in your program. It won't always work
because there are some places where new placeholders can't be added.
Make sure you understand why ALICE does what it does in the different
locations you try.

Pressing INS "inserts" new placeholders -- puts them in front of
something else. We can also "append" new placeholders. This is the
same as inserting except that the new placeholder is put down after the
thing that the cursor points to.

Move the cursor to the "i*i" of the "writeln" instruction and press
CTRL-E. You will see that a new Value placeholder is added after the
"i*i". In the same way, if you move the cursor to a variable name in a
declaration and press CTRL-E, you will get a new Name placeholder.
Pressing CTRL-E "extends" things like variable lists and lists of
declarations. Experiment with this until you are comfortable with it.

3.4. Deleting Things

If you've been experimenting with inserting and appending new
placeholders, you have a lot of empty placeholders in your program right
now. In this section, we'll learn how to get rid of those empty place-
holders and also how to delete other kinds of material.

Before you can delete something, you have to tell ALICE what you
want to delete. You do this by "sweeping out" the part of your program
that you want to disappear. Let's start simply. Move the cursor to an
empty Statement placeholder and press F10. We call this the SELECT key,
because you use it to select a part of your program. When you press the
key, you'll see the placeholder highlighted. ALICE always highlights
things you select, whether you are selecting an item from a menu or a
section of code to delete.

We'll get rid of this placeholder right away. Once the placeholder
is highlighted, press DEL. You should see the placeholder disappear.
The DEL key can be thought of as the DELETE key.

Now what happens if you select the wrong part of your program?
Nothing, because you can always "unselect" it. To unselect something,
just press F10 again. All the highlighting goes away and you can start
over. Just to try it, press F10 now and highlight any part of your
code. Press F10 again and all the highlighting goes away.

ALICE -9- The Personal Pascal

Now let's branch out a little. Your "var" declaration section
should have a declaration like this.

c : char; {A character}

Move the cursor to the type "char" in this declaration and select it by
pressing F10. You will see the word "char" light up. What happens when
you move the cursor to the left towards the variable name "c"? You
should see the whole declaration light up now. Try moving the cursor up
and down. You should see the lines around the declaration light up as
well. If you move the cursor far enough, you'll see the whole program
suddenly light up.

What is happening here? ALICE looks at the position of the cursor
and highlights the "smallest complete" block of Pascal code that "con-
tains" both the cursor and the thing the cursor was pointing to when you
pressed F10. If you start off at one declaration and move to an
adjacent one, ALICE highlights the two declarations. But what happens
if you move to the keyword var that starts the variable declaration sec-
tion? You'll see that ALICE highlights the complete variable declara-
tion section. If you highlight the start of a section, ALICE will
highlight the entire section and everything it contains, because ALICE
always highlights "complete" things. Sometimes the only complete block
of code that contains what you have swept out is the entire program, so
you will see the whole program light up.

For now, all we want to do is delete the declaration

c : char; {A character}

so move the cursor back to this line. You should see that the
highlighting shrinks again until only the declaration is highlighted.
Delete the declaration by pressing DEL again.

You can now delete all the empty placeholders in your program.
Just move to the placeholder, highlight it by pressing F10, then press
DEL. Do this to clean away all the placeholders you don't want.

Sometimes you want to delete something from your program but leave
a placeholder behind; in fact, sometimes you "must" leave a placeholder
behind to keep the program correct. To show what we mean, go to the
first line of the for loop

for i := 1 to 10 do begin

Move the cursor on top of the 10 and press F10. The 10 will light up.
What will happen if you press DEL? Try it.

You'll see that you get a Finish placeholder. Normally, pressing
DEL doesn't leave a placeholder when it deletes things. However, ALICE
has to leave a placeholder in this case. Without such a placeholder,
the for statement doesn't have the right form. (If you try this
deletion, press CTRL-U afterwards to UNDO it.)

ALICE -10- The Personal Pascal

There is a second command for deleting things from your program.
We call this command CLIP. To issue the CLIP command, highlight the
section of code that you want to delete, then press CTRL-P (the P stands
for "prune", a synonym for CLIP -- pruning and clipping hedges are the

same thing). The difference between the first Delete command and CLIP
is that CLIP "always" leaves a placeholder where the material was delet-
ed. Another difference is that you cannot clip anything that would have
to leave behind more than one placeholder. For example, if you have


you couldn't highlight both "i" and "i*i" and try to clip them, because
that would have to leave behind


For the same reason, you can't normally clip two consecutive statements;
you would have to DELETE them instead. CLIP leaves behind one and only
one placeholder. Generally, you only use CLIP for small single things,
like a parameter in a list being passed to a subprogram. (This is in
fact the most common use of CLIP.)

A special note: many ALICE commands, including DELETE and CLIP, let
you alter small things without highlighting them first. You can delete
what we call a "leaf" just by placing the cursor on it and doing a
DELETE or CLIP. A "leaf" is a simple thing that doesn't contain any
other things. Examples are variable names, constants, strings, comments
and placeholders.

4. How to go Further

On your disk you will find various sample programs written in
ALICE Pascal. You will get a menu of them if you ask to load in an
existing program from the startup menu. These include some simple
demos, some games (try "STARSHIP.AP") and some of the libraries of spe-
cial subroutines that come with ALICE. Play with these files and the
ALICE system in general. We hope that you will want to order your
complete copy of ALICE: The Personal Pascal today.

ALICE -11- The Personal Pascal


ALICE Summary for Experienced Users

This appendix summarizes ALICE for experienced computer users. Of
course, the main body of the manual gives a much more complete descrip-
tion of ALICE, but we recognize that experienced users often prefer to
experiment without bothering to read a lot beforehand. In order to
facilitate such experimentation, the following will give "bare bones"
descriptions of what you need to know first.

A.1. Templates

ALICE builds programs out of templates, i.e. skeletons of source
code. All templates have one or more placeholders to be filled in with
code. The way placeholders are represented depends on what kind of
screen you use. Colour screens show placeholders in blue; monochrome
show them more brightly than other source code. Enter source code in
placeholders and you often get a template with more placeholders. For
example, type for in a Statement placeholder and you get the template of
a for statement with more placeholders.

A.2. Tree Structure

Internally, ALICE represents the program in a tree structure that
represents the logic and grammar of Pascal. For example, a while state-
ment is a tree node that has a number of sub-trees: one for the Condi-
tion of the while and another for the list of statements contained in
the while loop. Both of these sub-trees may themselves be trees. The
Condition may be an expression represented as a tree, while the state-
ments may have many sub-trees of their own.

A.3. Menus

ALICE uses menus a great deal, especially menus of commands.
Menus are often called up by pressing keys or key sequences, e.g. the
function keys. The line at the top of the screen tells which menus are
associated with which function keys. F7 gives the menu of all menus.

All menu selections are labelled "A", "B", "C", etc. To choose a
selection from a menu, press the letter that labels that selection.

ALICE -12- The Personal Pascal

A.4. On-line Help

F9 is the general purpose Help Key. To get an explanation of a
particular menu selection, press the down-arrow keyuntil the selection
is highlighted, then press F9. If you press F9 when there is not a menu
on the screen, you will be shown the Help Menu. Of particular interest
is on this menu is "What Can I Type?". This gives a list of all possi-
ble inputs on the current placeholder. Choose one and it will be filled
into the placeholder. You can also press ALT-T to get this input list.

A.5. Selecting Code

Sometimes you must select a portion of code before issuing a
command. For example, before issuing ALICE's DELETE command you usually
have to select the portion of code to be deleted. To select a portion
of code, move the cursor to any part of the region you want to select
and press F10. Then use the arrow keys to move the cursor over more of
the code that you want to select. You will see this code highlighted
(in reverse video) on the screen. Selecting the start or end of a logic
structure automatically selects the whole of that structure; for exam-
ple, selecting the first line of a while loop automatically selects
everything that is contained in that loop (thanks to the tree structure
used to represent the program). Through cursor movements you can "sweep
out" all the code you want to select.

If you make a mistake, press F10 again. This "unselects" the
highlighted code and you can start again from scratch.

A.6. Getting New Placeholders

To get a new Statement or Declaration placeholder, move to the
line above the place where you want the placeholder and press ENTER. To
insert a placeholder in front of something, move the cursor to the
appropriate position and press INS. To add a new item to a list (e.g.
an argument list), just enter a comma. For more information, press F4
to get the Insertion Menu and use F9 to get more information about the
menu entries.


Press CTRL-U undoes the most recent change you made to your source
code. Pressing this again undoes the second most recent change, and so
on back several levels. Pressing CTRL-R "redoes" something that you
just undid. You can also issue the UNDO and REDO commands from the
Changes Menu -- press F5 to get this menu.

ALICE -13- The Personal Pascal

A.8. Editing Expressions

As you type a particular token, you may use backspace to delete
the character immediately preceding the cursor. The leftarrow key moves
the cursor backwards without deleting. CTRL-D deletes the character
under the cursor. The rightarrow key moves the cursor forwards without
deleting. CTRL-W deletes the word immediately preceding the cursor.

In general, ALICE takes some action as soon as you have completed
typing a single token. However, when you are entering expressions, com-
ments, and string constants, ALICE takes no action until you do some-
thing to move the cursor off the placeholder (e.g. press ENTER).

Once ALICE has taken an action, you cannot edit tokens using
backspacing, etc. Instead, you must select the piece of code you want
to edit and issue the EDIT command (from the Changes Menu or by pressing
ALT-E). You will then be able to edit what has been selected using
backspace, CTRL-D, the arrow keys, etc.

A.9. Workspaces

ALICE allows you to have several workspaces at one time, each con-
taining a program or part of a program. Commands on the Insert Menu
(F4), Delete Menu (F3), Changes Menu (F5), and Miscellaneous Menu
(SHIFT-F9) can change from one workspace to another as well as copy or
move code from one workspace to another. Often, workspaces are used as
holding areas as you move chunks of code around in your programs.

A.10. Errors

Syntax errors are almost impossible to generate, since most syntax
is controlled by ALICE's templates. Syntax errors can only occur if you
enter an expression incorrectly. As soon as you indicate that you have
finished typing the expression (by moving the cursor off the expres-
sion), ALICE will give you an error message and highlight the erroneous
expression on the screen.

For the most part, semantic errors are also detected as they are
entered. You can typecheck your program with the "Typecheck Program"
command from the Debug Menu (obtained by pressing F6). This is
necessary if you change a declaration, since ALICE will not automatical-
ly typecheck all occurrences of the changed symbol.

ALICE -14- The Personal Pascal

A.11. Non-Intuitive Changes

Some special changes (e.g. while loop to for loop) can be made us-
ing the "Special Changes" selection from the Changes Menu (F5). Other
changes can be made by moving code to a workspace and getting it back
later on. See the workspace commands mentioned above.

A.12. Symbol Name Completion

After you have typed the first few characters of a symbol name,
press End. ALICE will check all symbols defined in the current scope to
find which begin with the characters you have typed. If there is a sin-
gle name that matches, ALICE will complete the name you have started
typing. If there is more than one matching name, ALICE will give a menu
of all such names -- choose a name from this menu and ALICE will fill it
in where you were typing. This applies to built-in names like "integer"
and "writeln" as well as user-defined ones.

A.13. Other Features

For help on commands, call up a menu, highlight the appropriate
selection, and press F9. You can press F9 practically any time to ob-
tain explanations of various things.

Copyright (c) 1985, by Looking Glass Software.