Alice Pascal

This user guide describes the version of Alice that supports the Pascal programming language on the IBM-PC running MS-DOS. The version supported is Watcom Pascal, as described in WATCOM Pascal, Tutorial and Reference Manual by F.D.Boswell, T.R.Grove, and J.W.Welch. This is a superset of standard Pascal, i.e. it contains all the features of standard Pascal plus others as well.

We will not describe Pascal itself in this guide. For a description of Pascal, see the book just cited or any other Pascal reference guide -- book stores that sell computer reference material are sure to have several books on Pascal.

Looking Glass Software has published its own introduction to programming and Pascal, Learning to Program with Alice Pascal by Jim Gardner. We recommend this book because it covers a variety of topics concerning Pascal and computers, while giving hands-on experience with Alice. However, it is out of print. We may be able to make it available on the web.

Chapter 6 describes all those features of Alice Pascal that are not common in other versions of Pascal.

Conventions

Throughout the rest of this manual, we will use a number of shorthand conventions to make things simpler.

We use the term subprogram when something can be either a Pascal function or procedure. The term routine will also be used for this purpose.

When we write [F1], [F2], [F3], ..., we are referring to the function keys that run along the left side of the PC keyboard.

When we write [SHIFT-something], we mean that you should hold down one of the [SHIFT] keys, then press another key on the keyboard. For example, [SHIFT-TAB] means you should hold down the [SHIFT] key, then press [TAB]. For example, [SHIFT-F1] means that you should hold down a [SHIFT] key and press the key labelled [F1].

When we write [CTRL-something,] we mean that you should hold down the [CTRL] key and press some other key. For example, [CTRL-U] means that you should hold down the [CTRL] key and press the ``U'' key.

When we write [ALT-something], we mean that you should hold down the [ALT] key and press some other key. For example, [ALT-H] means that you should hold down the [ALT] key and press the ``H'' key.

Alice tries to represent different pieces of source code in different ways. If you have a colour display screen, the following colours are used.

normal text:white
placeholders:bold blue
errors:bold red
keywords:bold white
variables:white
named constants:white
comments:yellow
constants:white
user subprogram names:bold green
built-in subprogram names:cyan
record field names:white
undefined symbols:reverse video magenta
labels:white
expressions being edited:bright green

For systems with a ``monochrome display adapter'', the defaults are

placeholders:underlined
errors:reverse video
undefined symbols:reverse video
comments:bold
expressions being edited:underlined
everything else:normal

If you are using the ``colour/graphics display adapter'' with a non-colour (black and white) monitor, placeholders and expressions being edited are shown in boldface. In this manual, we will generally use the term ``highlighted'' to mean that something on the screen stands out somehow. If you have a colour screen, it will be shown in a special colour. If you have a monochrome screen, it will be shown in reverse video.

The Structure of Alice

In this section, we will look at some of the underlying technical principles of Alice.

Templates

Alice constructs programs using templates. A template is simply the skeleton of a structure in Pascal, with placeholders to indicate where information should be filled in. For example, a typical template might be

Screen Shot 6 8 whiletemp not available

Condition and Statement are empty placeholders that the user must fill in to get a complete while loop. Alice underlines placeholders or shows them in a special colour, depending on what kind of monitor display you are using.

Appendix C gives the complete list of templates used by Alice Pascal.

Internal Tree Structure

The code displayed on the screen will look like normal text. Internally, however, Alice stores programs in a tree format. The nodes of the tree are the various parts of the program. For example, there would be a node for the while loop given above. The sub-trees coming out of a node correspond to the placeholders. For example, there would be two sub-trees from the while loop node: one for the Condition placeholder, and one for the statements. Each of these sub-trees would consist of other nodes.

Some placeholders can be filled in with lists, while others cannot. The Statement placeholder in the while loop may be filled in with a list of statements; however, the Condition placeholder may only have a single Boolean condition. Nodes that are part of a list will be called list nodes.

At any given time, there is always one node that is the current node. This is the node pointed to by the cursor.

Expressions like

(c - d) * b + a

are also stored in a tree format, something like Polish notation. For example, the above expression would be stored in a tree as

           +
          / \
         /   \
        *     a
       / \
      /   \
     -     b
    / \
   /   \
  c     d

Expressions can be entered in this format; for example, if you are on an Value placeholder and type ``+'', Alice will expand things to

Value + Value

However, this is not very natural to most people. Therefore, Alice also lets you type expressions ``straight,'' as they would appear textually. This is done using a Simple Text Editor, explained later in this chapter.

Principles of Input

Alice knows what input is and isn't valid at every node. If you enter something that isn't valid for the current node, Alice will see if it IS valid for whatever contains the current node. If it is valid for the container, Alice will take the appropriate action; if not, Alice will see if the input is valid for the container's container, and so on up the tree.

For example, suppose you are in the executable part of a procedure and you type the keyword var (followed by a space). Alice knows this keyword is not valid anywhere in the executable part of the procedure, so it jumps up to the container (also called the parent).

This container is the full procedure declaration, not just the executable part. The keyword var is valid in the full declaration, signifying the start of the var declaration section. Therefore Alice will move the cursor to the var declaration section and prepare for input there.

You might use this kind of action, if you are in the middle of the code for a procedure and find that you forgot to declare a particular variable. No matter where you are, just type var and Alice will immediately go to the var declaration section where you can put your declaration.

Moving the Cursor

The position of the cursor indicates what part of the program you are editing at any particular time. By moving the cursor around, you can work on different parts of the program.

There are quite a few ways to move your cursor around the program. We will discuss the simplest here, and leave the rest for later in the manual, when we have described more of Alice.

Arrow Keys

The most straightforward way to move the cursor on the IBM PC is to use the arrow keys. Pressing a particular arrow key will move the cursor one position in the direction that the arrow points.

The [CTRL-rightarrow] Key

The [CTRL-rightarrow] key moves to the next empty placeholder in your program. If there are no empty placeholders between the current cursor position and the end of the program, Alice will wrap around to the start of the program and keep on searching for a placeholder.

The [CTRL-leftarrow] Key

The [CTRL-leftarrow] key moves to the empty placeholder that immediately precedes the current cursor location. Again, the search for a placeholder will wrap around from the top of the program to the bottom if need be.

For the purposes of [CTRL-rightarrow] and [CTRL-leftarrow], an erroneous piece of code counts as an empty placeholder, since it has not been filled in with something valid.

TAB

The TAB key moves the cursor a short distance forward in your program. In general, TAB goes to the next thing in the program that the user could change. For example, suppose the cursor is on the keyword for in

Screen Shot 7 11 forsq1 not available

Pressing TAB once will move to the i . Pressing TAB again will move to the 1 , skipping over the := . This is because the := is a necessary part of the for statement and cannot be changed. Pressing TAB another time will skip over to for the same reason, moving the cursor to the 10 . Pressing TAB one last time will skip over the do begin and move to the writeln instruction.

TAB will not wrap around when it reaches the bottom of the program. In user tests, it was found that people preferred not to have the wrap around in this instance.

SHIFT-TAB

SHIFT-TAB is the reverse of TAB. It moves the cursor backwards in the program. SHIFT-TAB will wrap around when it reaches the top of the program.

Menus

Much of the work you do with Alice can or must be done by selecting items from menus. A menu is just a list of possible operations that Alice can perform or objects (e.g. files, variables, or symbols) that Alice can work with. Menus are called up by issuing Alice commands, by pressing certain keys (e.g. function keys), or by selecting certain items from other menus.

Menu Lay-out

All menus have the same general appearance. They are displayed in the bottom right corner of the screen. The first line of the menu is a heading of some sort. It stands out visually from the rest of the menu, in reverse video (with dark letters on a bright background).

The lines that follow are the selections of the menu. The selections are labelled "A", "B", "C", etc. One of the selections is made to stand out from the rest in the same way that the heading stands out. We say that this selection is highlighted. When a menu is first called up, the first selection is the one that is highlighted, but the user can change this in various ways that are described below.

In this manual, we will usually omit the letters that label menu selections.

Making a Menu Selection

There are several ways to tell Alice which menu selection you want to choose.

On the PC, the easiest way is to press the letter that corresponds to the selection you want. For example, if you want the selection that is labelled "C", press the C key.

Another way to choose something from a menu is to highlight the selection you want. As noted previously, menus always have one selection highlighted already. By pressing the up or down arrow keys, you can highlight different selections on the menu. When you have highlighted the correct selection, press the spacebar to tell Alice this is the one you want. (If you don't want to press the spacebar, Alice will let you press practically any key on the main keyboard, provided you don't press letters that are selection labels or special keys like the function keys.)

If you are choosing menu selections by highlighting them, Alice offers several quick ways to move through menus quickly. Pressing END immediately highlights the last selection on the menu. Pressing HOME immediately highlights the first selection. Pressing the PgDn key jumps down several selections, and pressing PgUp jumps up several selections.

The Do Nothing Selection

Most menus have a selection labelled Do nothing . Choosing this selection will return you to whatever you were doing before you summoned up the menu. In most cases, the Do nothing selection will be the one that is highlighted when the menu is first displayed on the screen, so you can just press the spacebar if you called up the menu by mistake.

Menu Scrolling

Some menus are too long to fit on the display screen. When this is the case, Alice shows as much of the menu as possible and puts the highlighted word MORE at the bottom of what is shown. To see more of the menu, press the arrow keys to go beyond the end of what you see. Alice will scroll up the menu -- the top selections of the menu go off the top of the screen to make room for more selections at the bottom. The PgDn and END keys are particularly useful for moving beyond what you see on the screen. Remember that END always goes to the last thing on the menu (even if you can't see it yet), and PgDn jumps down to new selections.

Alice Commands

Alice has a large number of commands, controlling the various aspects of Alice operation. Most commands can be invoked in several ways.

Command Lines

The most primitive way to issue a command is by typing the command explicitly. To do this, start by pressing the [CTRL-X] key (called the command key). When [CTRL-X] is pressed, Alice will move the cursor to a special command line at the bottom of the screen, and prompt with a > . You will then be able to type the command name, plus any arguments that the command may take. For example, you might type the command

save filename

to save a program in the named file.

As you are typing the command line, you may use Alice's standard text editing facilities described later in this chapter. When you have finished typing the line, press [ENTER] and Alice will execute the command.

Command Menus

To help users avoid a lot of typing, Alice lets you execute commands from menus instead of typing them explicitly. There are a number of command menus, each containing a group of related commands. For example, there is a menu for the commands that perform file operations, a menu for the commands that control debug features, and so on.

Command menus can be called up in a number of ways.

  1. You can press the command key [CTRL-X] and enter a command that explicitly calls up a command menu.
  2. You can press the [F7] key. This gives you a menu of all the other command menus. Choose a selection from this menu (using the menu selection techniques discussed earlier in this chapter) and you will be shown the appropriate command menu.
  3. Press a ``menu-summoning'' key. Most of the command menus can be called up by pressing a particular key. For example, pressing [F9] gives you the Help Menu. The keys that call up the various menus are given in Chapter 4.

Once you have called up the appropriate command menu, you may execute any command from the menu by choosing it with the normal menu selection techniques (i.e. by pressing the key that labels the command, or by highlighting the command and pressing the spacebar).

Command Key Sequences

In order to make work with Alice even faster, the most commonly used commands have been bound to certain keys or key sequences. Pressing the appropriate key tells Alice to execute the associated command. For example, we have mentioned that pressing [F7] calls up the menu listing all the command menus. This works because the [F7] key has been bound to the MENU command. When you press [F7], Alice carries out the MENU command and gives you the menu of all command menus.

When Alice starts up, standard key bindings are obtained from a file named ``ap.ini'' in the root directory. You may change the standard set of bindings by changing ``ap.ini''. You may also create new key bindings of your own in two ways.

  1. Using the MAP command (described in Chapter 4).
  2. Using the ``m='' option on the command line that invokes Alice (described in Chapter 5).

For the purposes of this manual, we will assume that everyone uses the default key bindings that come with the Alice package.

Selecting Pieces of Code

Before some Alice commands may be issued, the user must select a portion of the source code for the command to work on. For example, when you wish to delete a part of your program, you must select the code that you want to delete and then issue the DELETE command.

The code selection process is strongly influenced by the tree structure used to represent the program internally. When you select a particular node, you also select all the sub-trees of that node. To put this less technically, when you select any piece of code, you automatically select anything that the code logically contains. For example, when you select a while loop, you automatically select all the statements that are contained in that loop.

To select a piece of code, follow these steps.

  1. Move the cursor to the section of code you want to select.
  2. Press [F10]. This is called the select key. Alice will highlight the code under the cursor. This will be the smallest piece of code that contains the cursor position. For example, consider
  3. for i := 1 to 10 do begin
        iarr[i] := 0;
        end;
    

    If the cursor is on the := of the iarr assignment statement, the whole assignment will be highlighted, because this is the smallest piece of code that can logically contain the := . If the cursor is on the ``0'' of the assignment statement, only the ``0'' will be highlighted (because the right hand side of the assignment is a node all on its own). If the cursor is on the for of the for loop, the entire loop will be highlighted.

    Adjust the section of code that has been selected. This is done by moving the cursor across the statements or the part of the statement that you wish to select. Remember that if you select an entire statement, you select everything that the statement contains as well.

Once you see the correct section of code highlighted, you may execute any of the commands for which you must select a section of code.

Moving the cursor can increase the amount of code that is selected. Moving the cursor to another element of the list that contains the highlighted code will highlight every list element from the cursor to what was already highlighted. Moving the cursor to something outside the list that contains the highlighted code will highlight the smallest node that contains the cursor and what is already highlighted. For example, if you have already highlighted a line in a while loop, then move the cursor to the Condition of the while loop, Alice will highlight the entire while loop, because this is the smallest node that contains both the while condition and the highlighted line.

You should experiment with code selection until you are comfortable with the way it works. All this becomes very easy to follow when you are using Alice on the computer.

Note that some commands will only work on a particular kind of code section. For example, the EDIT command will only work on expressions, comments and symbols, while the HIDE command will only work on a list of complete lines. The descriptions of the individual commands later in this guide will give more details on this.

Unselecting

If you do not succeed in highlighting the section of code that you want, press [F10] again. This ``unselects'' the code. The highlighting will go away and you can start over.

Workspaces

Alice stores the code for a program (or part of a program) in a workspace. During your Alice session, you may create any number of workspaces, each containing its own code.

Workspaces are identified by names that follow the usual rules for names in Pascal. When you first start Alice, you are placed in a workspace called ``main''. During the session, you may issue commands to create new workspaces or to go back and forth between existing workspaces. There are also commands that allow you to copy or move code from one workspace to another. These are described in Chapter 4.

There is no explicit way to delete a workspace. However, you can copy or move an empty placeholder to a workspace, thereby shrinking it to a point where it uses almost no memory.

The Simple Text Editor

The Simple Text Editor is at work whenever you are entering input. It offers a variety of simple ways to edit what you are typing and correct typing mistakes.

Typing a backspace deletes the character immediately preceding the cursor. Several backspaces in a row will delete several characters. You will see them disappear as you backspace. Thus if you realize that you have made a typing mistake, you can often correct the mistake by backspacing and retyping.

The leftarrow key moves the cursor back one position without deleting anything. Using this key you can move the cursor back into the middle of what you were typing, then type new material. This new material will be inserted at the cursor position, and everything to the right of the cursor will be moved over to make room.

Typing CTRL-D deletes the character underneath the cursor. Thus if you are in the middle of a line, typing CTRL-D several times can remove something from the middle of the text.

The rightarrow key moves the cursor forward one position without deleting anything. Thus if the cursor is in the middle of the line, you can use the rightarrow key to get back to the end of the line.

CTRL-W deletes the word or part-word that immediately precedes the cursor. Thus if you are typing a word and press CTRL-W, you will delete as much of the word as you have typed.

Symbol Completion

When entering code, you can reduce the amount of typing you have to do by using the symbol completion feature. Whenever you are entering a symbol (the name of something, like a variable or subprogram), you may type the first few characters and then press [END]. Alice will go through all the names that are currently defined to see which ones begin with the characters you have typed. If there is only one name that matches, Alice will automatically complete the name you have typed. If there are several names that match, Alice will offer a menu showing all the matches. Choose the appropriate name from this menu and Alice will complete what you have started to type.

Note that this means you can use long and descriptive names in your program without a lot of typing. The first time you use the name, you have to type it out in full. From that point onward, just type the first few characters, then press [END] to type the rest.

Pressing [END] also works for built-in names. For example, if you want to say that a variable has the type integer , just enter int , then press [END] to type the rest.

The symbol completion feature only checks symbol names that are defined in the scope that contains the cursor. For example, if you are entering code inside a procedure and press [END], Alice will not check names that are local to other functions and procedures. Also if you have an expression that involves a record field name, Alice will not be able to complete the field name unless you started with a Field placeholder and you have already filled in the name of a record variable.

Special Cases

Much of the time, the Simple Text Editor collects one token at a time. This means that it collects letters, digits, and underscore characters until it encounters a special character. For example, if you are filling in a Variable placeholder, the editor will keep on collecting characters for the name until you type a space or some other character that doesn't belong in a variable name. When it has a complete token like this, the Simple Text Editor passes the token on so that other Alice routines can decide what to do with it.

Once the Simple Text Editor has passed the token on, the editing facilities cannot be used to edit that token. For example, if you type a variable name and then a space, the name is usually handed to other Alice routines and you can't just backspace to delete characters in the variable name.

However, there are some instances where typing a space or some other character does not terminate simple text editing. These are

  1. when you are entering a comment
  2. when you are entering a string constant
  3. when you are entering an expression in a Value or Condition placeholder
  4. when you are editing something using the EDIT command (described in Chapter 4).

In all these cases, Alice will keep on collecting what you type even if you type space characters or other things that separate tokens (e.g. operators like + or div). This means that you can enter expressions, strings, etc. and use the Simple Text Editor to edit them in their entirety, instead of dealing with them token by token. To tell Alice that you are finished entering an expression, string, etc., you must move the cursor off the expression (or whatever) with one of the cursor movement keys (e.g. TAB or an arrow key). Another way to terminate expressions is to type whatever comes after the expression in the program: a keyword like to or then, or a character like a comma or closing parenthesis.