Programming

PawCalc is a programmable calculator. This means that you can write programs in a simple programming language and PawCalc will then execute them. Programs are written as memos in the 'PawCalc'. The middle popup list of the three vertical ones displays the programs available. If the list is empty, follow the instructions in the Installation section to install one or more sample programs. You run a programs by selecting it from the list.

Each program memo starts with a one-word name. This is the name that shows up in the popup list. Then follows a series of semicolon separated statements. Execution starts with the first statement. The next statement to be executed is normally the one directly following the previously executed statement. However, some statements transfer control to other parts of the program. PawCalc understands the statements below. "EXPR" indicates an expression which can be calculated, like "1+2*3". Anything in square brackets is optional. "VAR" is a variable name, and "LABEL" is a text string. Comments are between "/*" and "*/" and can be placed almost anywhere.

EXPR;                     // Compute expression. Result in 'ans'.
label LABEL;              // Mark current program location.
store VAR [EXPR];         // Store a value in variable VAR. The value
                          // is the result of EXPR. If no expression
                          // is given, 'ans' is used.
store VAR "EXPR;EXPR;...;EXPR;";   // Stores values in an indexed variable.
                                   // For example, store x "0;1;2;";
                                   // stores 0 in x0, 1 in x1, and 2 in x2.
index VAR [EXPR];         // Retrieves a value from an indexed variable.
                          // For example, "index x 10+32;" retrieves
                          // variable "x42"; If no expression is given,
                          // 'ans' is used.

jz LABEL;                 // Jump to LABEL if 'ans' is zero.
jnz LABEL;                // Jump to LABEL if 'ans' is not zero.
jp LABEL;                 // Jump to LABEL if 'ans' is positive.
jn LABEL;                 // Jump to LABEL if 'ans' is negative.
jmp LABEL;                // Unconditional jump to LABEL.

sz LABEL;                 // Subroutine jump to LABEL if 'ans' is zero.
snz LABEL;                // Subroutine jump to LABEL if 'ans' is not zero.
sp LABEL;                 // Subroutine jump to LABEL if 'ans' is positive.
sn LABEL;                 // Subroutine jump to LABEL if 'ans' is negative.
sub LABEL;                // Unconditional subroutine jump to LABEL.

return;                   // Return from subroutine.
end;                      // End program.

say "TEXT";               // Display TEXT on the screen.
ask "TEXT";               // Display TEXT and wait for a reply.
                          // The reply is evaluated as an expression
                          // and placed in 'ans'.
                          // The TEXT arguments for both 'say' and 'ask'
                          // are expanded as follows:
                          // %% : %
                          // %VAR% : value of variable VAR
                          // \n, \t : newline, tab
                          // You can append multiple text strings by
                          // writing them next to each other:
                          // say "Hello " "World";

// The following commands change the preferences. If no argument is given,
// the value of 'ans' is used.

set precision [0-9];
set format [0-6];         // 0=1000.00,  1=1000,00,  2=1,000.00, 3=1.000,00,
                          // 4=1 000,00, 5=1'000.00, 6=1'000,00
set zeros [0 | 1];
set mode [0-4];           // 0=norm, 1=sci, 2=eng, 3=frac, 4=mixed.
set base [2 | 8 | 10 | 16];
set degrees [0 | 1];

// The following commands read the preferences and place the result
// in 'ans'.

get precision;
get format;
get zeros;
get mode;
get base;
get degrees;

delete VAR;               // Deletes variable VAR.
exists VAR;               // Returns in 'ans' 0 (variable VAR does not
                          // exist) or 1 (VAR exists).
      

See the "programs.txt" file for sample programs.

After the execution of a program, the result is stored in 'ans' and displayed on the screen. Actually, the result of each statement is stored in 'ans'; with the exception of the jump and subroutine commands, 'delete', 'label', 'store', 'return', 'end', 'say', and 'set' which do not change 'ans'.

The programs interpret numbers according to the settings in the PawCalc preferences. For example, the statement "1,000 - 1" will compute either 999, 0, or an error depending of the settings. Use the "get format" and "set format" commands if this causes problems:
get format;
store f;
set format 3
/* Do computations ... /*
set format f
        

You can interrupt the execution of a program by tapping the screen.

Program statements can also be written on the expression line and executed by pressing 'EXE'.