Awlfree

The Awlfree syntax concept illustrated with arithmetical examples

The Awlfree syntax concept has three kinds of constructs Terminated, Rambling, and Polish.

Terminated constructs end with a reserved word. Two examples from Algol68

if . then ... else ... fi

or

while . do ... od

The closer, fi, solves the dangling else problem. What does the PASCAL style

if A then if B then C else D

actually mean? If closers are required, this must be written as either

if A then if B then C fi else D fi

or as

if A then if B then C else D fi fi

Notice that clarity has a price: the ugly pile up of closers.

Let us use simple examples, even if they show Awlfree in a bad light. We can add four numbers with

sum 1 2 3 4 mus

which evaluates to 10. Or multiply them

prod 1 2 3 4 dorp

getting 24. Let us nest multiplication inside addition. 1×2+3+4 becomes

sum prod 1 2 dorp 3 4 mus

which evaluates to 9. Saying the result of evaluating a construct adds clarity, so is worth a little notation. We write

sum prod 1 2 dorp 3 4 mus => 9

and write 1+2×3+4 as

sum 1 prod 2 3 dorp 4 mus => 11

But for 1+2+3×4 we encounter the distinctive rule Awlfree. We are not permitted to pile up closers, but must use a Rambling Construct. A Rambling Construct is a version of a terminated contruct that uses different reserved words and lacks the final closer. It extends as far to the right as it can. That is, a rambling construct is only used within an enclosing construct and ends with a reserved word of that enclosing construct. The rambling version of prod ... dorp is mul ...

So we can write 1+2+3×4 as

sum 1 2 mul 3 4 mus => 15

and 1×2+3×4 as

sum prod 1 2 dorp mul 3 4 mus => 14

Notice the juxtaposition dorp mul of the fifth and sixth tokens. There is only the space that splits dorpmul into two tokens. There is no generic separator or terminator, no semi-colon.

The rambling version of sum ... mus is add ...

Normal arithmetic uses infix notation and precedence

(1+2)×(3+4) = 21

1+2×3+4 = 11

How do we write (1+2)x(3+4) in Awlfree? There is no generic bracket, brace, or parenthesis. But none is needed, we just write

prod sum 1 2 mus add 3 4 dorp => 21

Notice how dorp terminates both prod ... 4 dorp and add 3 4 dorp. Notice also the juxtaposition of mus add. The terminal reserved word mus terminates one construct, while the initial reserved word add starts the next one. In effect the juxtaposition separates the two numbers 3 (from 1+2) and 7 (from 3+4) that are to be multiplied together.

All these closers are too heavy weight for simple arithmetic. Awlfree has Polish constructs: add2 adds two numbers. add3 adds three numbers.

add2 5 7 => 12
mul2 5 7 => 35
add3 5 7 10 => 22
mul3 5 7 10 => 350

We could have written 1x2+3x4 in Awlfree as

add2 mul2 1 2 mul2 3 4

And (1+2)x(3+4) as

mul2 add2 1 2 add2 3 4

All free constructs can be nested as deeply as required. So 1+2x3+4x(5+6) might be

sum 1 mul2 2 3 mul2 4 add2 5 6 mus

The rule about not piling up closers still applies

add2 5 6 = sum 5 6 mus = add 5 6

but we are forbidden to replace add2 5 6 by sum 5 6 mus because it would lead to a pile up mus mus. But we can write

sum 1 mul2 2 3 mul2 4 add 5 6 mus

and even

sum 1 mul2 2 3 mul 4 add 5 6 mus

but beware

sum 1 prod 2 3 dorp mul 4 add 5 6 mus

is permitted and means the same. But

sum 1 mul 2 3 mul 4 add 5 6 mus

is permitted and means something different. Adding in the parenthesises implicit in the way that rambling constructs extend as far to the right as they can

sum 1 (mul 2 3 (mul 4 (add 5 6))) mus

we realise that this is actually 1+2x3x4x(5+6) and definitely not 1+2x3+4x(5+6).

The interpretation of sum 1 mul2 2 3 mul 4 add 5 6 mus is a little subtle. What happens without the rule against closers piling up? We might to tempted to write

sum 1 prod 2 3 dorp prod 4 sum 5 6 mus dorp mus

I believe that the pile up of closers "mus dorp mus" is supposed to add certainty, but in practise, it baffles the eye, and readers just nod it through. If it is

sum 1 prod 2 3 prod 4 sum 5 6 mus dorp dorp mus

with the dorp in the wrong place, making it 1+2x3x(5+6), no-one will notice, because knots of closers "mus dorp dorp mus" or "mus dorp mus" just get taken on trust as an aspect of human psychology.