Contents of the ALICE.DOC file

ALICE -1- The Personal Pascal

1. Introduction

This file contains excerpts from the ALICE documentation. To geta general idea of what ALICE does, we suggest you first run the demons-tration session according to the instructions on your demo disk. Thisdocument is mostly Chapter 3 of our Tutorial guide. As such, it assumesyou have gone through the introduction in Chapter 2. This first sessionis very similar to the start of the demonstration session, so you shouldbe 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 thecomplete version of ALICE. If you're an experienced programmer, thesemanuals will be important because they contain not just information onusing Alice, but technical details, including information on customizingAlice to make it easy and fast to use for more sophisticated program-mers.

ALICE: The Personal Pascal is a total computing environment thatmakes 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 texteditor, the ALICE program editor is intimately linked to a specificprogramming language. The editor knows the syntax of the language andmakes it virtually impossible for the user to enter a syntax error. Atevery stage in the programming process, users have a syntacticallycorrect 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 forthe programming language. The interpreter can run more quickly thanother interpreters, because the program editor automatically parses userinput as the program is being entered.Internally, the program isstored in a tree structure that makes the interpreter's job very easy.

The debugger is linked to the interpreter and the editor, and canmake 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 canspeed the debugging process immensely, because it allows users to "getinside" their programs as the programs run.

As another example of the interplay between debugger, interpreter,and editor, ALICE supports "cursor-following".While the program isexecuting, 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 thisan excellent tool for visualizing program logic, but it can also aid inlocating problems in the program's code.

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

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

Users can either type in one of the possibilities named in themenu, 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. Programsmay be written from menus; HELP is chosen from a Help Menu; and allALICE commands may be executed from menus. ALICE commands may also be"bound" to keys, so the commands can be executed simply by typing theappropriate key. ALICE comes with a set of default bindings, but userscan set up their own bindings if they prefer. Indeed, users can bindany character sequence to any key, making common operations extremelyeasy to enter.

All these factors combine to make ALICE a unique programming andeducational tool. The word "unique" is important. Some program editorswere developed before ALICE, but most of these were prototypesconstructed at universities (notably Cornell).We know of no product onthe market that offers the comprehensive facilities available throughALICE.However, it is only a matter of time before ALICE and softwarelike it make their impact on the programming world. By offering anentirely new approach to the preparation of programs, ALICE gives usersthe chance to concentrate on the "important" aspects of programming andto 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 theimportant features of ALICE to get you going if you're an experiencedprogrammer.

2. First Session

If you have run the demonstration, you should already have an ideaof how to enter and run a simple program with ALICE. You may want to gothrough 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 theStarting Menu (that appears when you first run the ALICE program), youwill find several selections that can help you use ALICE. The mostimportant is "What is ALICE all about?".

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

3. Exploring ALICE

In this chapter, we'll walk through some more simple editingoperations using ALICE. Again, you should follow along on the computeras 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 thingto do is to get the program back from the file. This process is called"loading".

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 arrowkey until the selection you want is highlighted, and then press thespace 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 knowsthat this file contains an ALICE Pascal program because of the ".ap" onthe 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 onthe terminal screen.

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

Now that you've loaded the program, you can run it or single stepthrough it again if you like. To run it normally, press F1; to singlestep, 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 thechapter depend on the position of the cursor. Because of this, we'regoing to spend some time describing different ways to move the cursoraround 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 otherkeys that may also be useful.

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

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

for i := 1 to 10 do begin writeln(i,i*i); end;

If you press TAB once, you will move to the "i", because the "i" couldbe changed to a different variable name. If you press TAB again, thecursor will jump to the number "1". It skips over the ":=" because thatcan't be changed; it always has to be there in the for statement. Keeppressing TAB and the cursor will keep jumping forward.It skips overthe to (which can be changed to downto but only in a special way), overthe do begin and over the end.These are skipped because they are partof 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 theusual 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 movebackwards through all the user-entered things in your program.Try it.

The ENTER key is like the carriage return on a typewriter. Whenyou 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 ofyour program (before the for loop) and press ENTER. You will see thatALICE creates a new Statement placeholder before the for loop.If youpress ENTER again, ALICE will stay on the Statement placeholder it hasjust made. Move the cursor to the keyword for and press ENTER. Thistime, 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 appropriateplaceholder there (if there isn't one there already). If you are in adeclaration section, this new placeholder will be a declaration place-holder; if you are in the executable part of your program, it will be aStatement placeholder.If the cursor is already on a placeholder of theappropriate type, pressing ENTER does nothing.Thus, ENTER always givesyou 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 somethinglike TAB and SHIFT-TAB, in that they jump through the program."CTRL-rightarrow" will jump "forward" to the nearest empty placeholder in theprogram, while "CTRL-leftarrow" will jump "backward" to the nearestempty placeholder. Use ENTER to create a few empty placeholders in yourprogram 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 endof 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'tbeen declared.) Error-highlighted things are almost the same as emptyplaceholders; they aren't correct Pascal, so ALICE behaves as if theystill 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 editingoperations: adding things to a program, deleting things from theprogram, and changing things that are already there.

We'll start with adding things. The most common things to add areprobably statements and declarations. To add a statement, you need tomake 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.} var i : integer; {A counter} begin for i := 1 to 10 do begin writeln(i,i*i); end; end.

Let's add a "writeln" instruction before the for loop so we can printout a heading before the list of numbers. The easiest way to do this isto move the cursor to the word begin before the for statement and pressENTER.As you've seen before, the cursor will jump down a line andcreate 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 itworks.

Now move to the declaration for "i" in the declaration section andpress ENTER. The cursor will move down a line, and this time create anempty 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 filledin this sort of thing when you set up the declaration for "i".

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

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. Movethe 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 fillthis 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 thesmallest 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 INSagain.ALICE sees that you are pointing to a data type and asks if itmakes sense to add another Type placeholder here. Of course, itdoesn't, because

var name : type, type;

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

var Variable-Declaration i : integer; {A counter}

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

writeln(i,i*i);

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

writeln(Value,i,i*i);

Why? Because you were pointing to "i" which filled in a Value place-holder, so ALICE could insert the same sort of placeholder. Whathappens 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". Youget the smallest kind of placeholder that can be inserted here. Just tomake sure you know what's happening, move the cursor to the "i*i" andpress INS again. You'll insert a Value placeholder. Make sure youunderstand why.

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

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

Move the cursor to the "i*i" of the "writeln" instruction and pressCTRL-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 adeclaration and press CTRL-E, you will get a new Name placeholder.Pressing CTRL-E "extends" things like variable lists and lists ofdeclarations. Experiment with this until you are comfortable with it.

3.4. Deleting Things

If you've been experimenting with inserting and appending newplaceholders, you have a lot of empty placeholders in your program rightnow. 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 youwant to delete. You do this by "sweeping out" the part of your programthat you want to disappear. Let's start simply. Move the cursor to anempty 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 thekey, you'll see the placeholder highlighted. ALICE always highlightsthings you select, whether you are selecting an item from a menu or asection of code to delete.

We'll get rid of this placeholder right away. Once the placeholderis 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 startover. Just to try it, press F10 now and highlight any part of yourcode. Press F10 again and all the highlighting goes away.

ALICE -9- The Personal Pascal

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

c : char; {A character}

Move the cursor to the type "char" in this declaration and select it bypressing F10. You will see the word "char" light up. What happens whenyou move the cursor to the left towards the variable name "c"?Youshould see the whole declaration light up now.Try moving the cursor upand down. You should see the lines around the declaration light up aswell. If you move the cursor far enough, you'll see the whole programsuddenly light up.

What is happening here? ALICE looks at the position of the cursorand highlights the "smallest complete" block of Pascal code that "con-tains" both the cursor and the thing the cursor was pointing to when youpressed F10. If you start off at one declaration and move to anadjacent one, ALICE highlights the two declarations. But what happensif 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 willhighlight the entire section and everything it contains, because ALICEalways highlights "complete" things. Sometimes the only complete blockof code that contains what you have swept out is the entire program, soyou 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 thehighlighting 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 pressDEL. Do this to clean away all the placeholders you don't want.

Sometimes you want to delete something from your program but leavea placeholder behind; in fact, sometimes you "must" leave a placeholderbehind to keep the program correct. To show what we mean, go to thefirst 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, pressingDEL doesn't leave a placeholder when it deletes things. However, ALICEhas to leave a placeholder in this case. Without such a placeholder,the for statement doesn't have the right form.(If you try thisdeletion, 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 thesection of code that you want to delete, then press CTRL-P (the P standsfor "prune", a synonym for CLIP -- pruning and clipping hedges are the

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

writeln(i,i*i);

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

writeln(Value,Value);

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

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

4. How to go Further

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

ALICE -11- The Personal Pascal

APPENDIX A

ALICE Summary for Experienced Users

This appendix summarizes ALICE for experienced computer users. Ofcourse, the main body of the manual gives a much more complete descrip-tion of ALICE, but we recognize that experienced users often prefer toexperiment without bothering to read a lot beforehand.In order tofacilitate 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 sourcecode. All templates have one or more placeholders to be filled in withcode. The way placeholders are represented depends on what kind ofscreen you use. Colour screens show placeholders in blue; monochromeshow them more brightly than other source code. Enter source code inplaceholders and you often get a template with more placeholders. Forexample, type for in a Statement placeholder and you get the template ofa for statement with more placeholders.

A.2. Tree Structure

Internally, ALICE represents the program in a tree structure thatrepresents 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 inthe while loop. Both of these sub-trees may themselves be trees. TheCondition 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. thefunction keys.The line at the top of the screen tells which menus areassociated with which function keys. F7 gives the menu of all menus.

All menu selections are labelled "A", "B", "C", etc. To choose aselection 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 aparticular menu selection, press the down-arrow keyuntil the selectionis highlighted, then press F9.If you press F9 when there is not a menuon the screen, you will be shown the Help Menu. Of particular interestis 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 filledinto 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 acommand. For example, before issuing ALICE's DELETE command you usuallyhave to select the portion of code to be deleted. To select a portionof code, move the cursor to any part of the region you want to selectand press F10.Then use the arrow keys to move the cursor over more ofthe 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 logicstructure automatically selects the whole of that structure; for exam-ple, selecting the first line of a while loop automatically selectseverything that is contained in that loop (thanks to the tree structureused to represent the program). Through cursor movements you can "sweepout" all the code you want to select.

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

A.6. Getting New Placeholders

To get a new Statement or Declaration placeholder, move to theline above the place where you want the placeholder and press ENTER. Toinsert a placeholder in front of something, move the cursor to theappropriate 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 F4to get the Insertion Menu and use F9 to get more information about themenu entries.

A.7. UNDO

Press CTRL-U undoes the most recent change you made to your sourcecode. Pressing this again undoes the second most recent change, and soon back several levels. Pressing CTRL-R "redoes" something that youjust undid. You can also issue the UNDO and REDO commands from theChanges 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 deletethe character immediately preceding the cursor. The leftarrow key movesthe cursor backwards without deleting.CTRL-D deletes the characterunder the cursor. The rightarrow key moves the cursor forwards withoutdeleting. CTRL-W deletes the word immediately preceding the cursor.

In general, ALICE takes some action as soon as you have completedtyping 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 usingbackspacing, etc. Instead, you must select the piece of code you wantto edit and issue the EDIT command (from the Changes Menu or by pressingALT-E). You will then be able to edit what has been selected usingbackspace, 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 ormove code from one workspace to another. Often, workspaces are used asholding areas as you move chunks of code around in your programs.

A.10. Errors

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

For the most part, semantic errors are also detected as they areentered. You can typecheck your program with the "Typecheck Program"command from the Debug Menu (obtained by pressing F6).This isnecessary 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). Otherchanges can be made by moving code to a workspace and getting it backlater 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 tofind which begin with the characters you have typed. If there is a sin-gle name that matches, ALICE will complete the name you have startedtyping. If there is more than one matching name, ALICE will give a menuof all such names -- choose a name from this menu and ALICE will fill itin 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 appropriateselection, and press F9. You can press F9 practically any time to ob-tain explanations of various things.