1.1 Exercise 1: The basics - editing and compiling

In this exercise we will construct a program that reads a list of integers and prints the minimum and maximum value.

Choose 'File->New BETA Program...' Name the program 'minmax.bet'.

[3kb 485x148 PNG]


The <<PrefixOpt>> in the Form window means that you can type a super pattern here. We do not want that here, so click <<PrefixOpt>> and press Delete.

The <<AttributeDeclOpt>> means that you can declare attributes here. The program needs two integers: min and max.

Click <<AttributeDeclOpt>> and type min,max: @integer. Choose 'Edit->Parse Text' or press Ctrl+space to leave text editing mode.

The <<ImpOpt>> means that you can type imperatives here. We need to initialize min and max, so click <<ImpOpt>> and type maxint->min; minint->max. Leave text editing mode.

Now we need a loop. Mark minint->max by holding down the mouse button from the middle of minint to the middle of max .

[3kb 472x137 PNG]


Then append some "empty code" by choosing 'Edit->Insert After' or by pressing Enter.

[3kb 533x137 PNG]


Replace the <<ImpOpt>> by myloop: (# do restart myloop #). Leave text editing mode.

[4kb 537x140 PNG]


Mark myloop as shown above and re-enter text editing mode by pressing Ctrl+space or F2. Type the code in the loop, so that it looks like this:

[6kb 571x363 PNG]


Is the program correct?

Find out by checking it: choose 'Compile/Run->Check Current (minmax)' or click on the Check button [622 bytes 32x18 PNG] in the toolbar. If there are errors in the program a window showing the errors will appear:

[9kb 417x345 PNG]


You can click the 'Nodes' list to browse through the errors. At the bottom of the window information on the error is displayed: "i is not declared". Insert a declaration of i by clicking on max and inserting "empty code" (using menus or pressing Enter). Type i and leave text editing mode.

[6kb 571x363 PNG]


Check the program again. This time it should work.

Now we insert a few statements that print the results of the loop. Mark all of myloop and insert some "empty code" after the loop and add the lines shown below:

[5kb 571x274 PNG]


Compile [505 bytes 32x18 PNG] and run [637 bytes 32x18 PNG] the program from the Mjolner tool (NOT in a shell). You can interact with the program in the shell where the Mjolner tool was started.


Mjolner Tool Workshop
© 2001-2004 Mjølner Informatics
[Modified: Thursday September 13th 2001 at 18:47]