Malvern Algol68 to C

Implementation of programming language Algol68

This Algol 68RS compiler developed by the UK Defence Research Agency. It implements almost all of the language known as Algol 68, and extends that language in minor respects. This version of the 68RS compiler generates code in the programming language ‘C’, which then can be compile and run on Intel based linux.

Examples:

Factorial:

Example for versions Algol68g-1.18.0, Algol68toc-1.8

This example uses recursive factorial definition with first 7 numbers precomputed.

PROC factorial = (INT n)LONG LONG INT:
  CASE n+1 IN
    1,1,2,6,24,120,720 # a brief lookup #
  OUT
    n*factorial(n-1)
  ESAC
;

Fibonacci numbers:

Example for versions Algol68g-1.18.0, Algol68toc-1.8

Generative method. This code specimen uses a callback to generate the sequence on demand.

MODE YIELDINT = PROC(INT)VOID;

PROC fibonacci = (INT n, YIELDINT yield)VOID: (
  INT even:=0, odd:=1;
  yield(even);
  yield(odd);
  FOR i FROM odd+1 TO n DO
    yield( (ODD i|odd|even) := odd + even )
  OD
);

main:(
  # FOR INT n IN # fibonacci(16, # ) DO ( #
  ##   (INT n)VOID:(
        print((" ",whole(n,0)))
    )); # OD # 
    print(new line)
)

Fibonacci numbers:

Example for versions Algol68g-1.18.0, Algol68toc-1.8

Analytic method

PROC analytic fibonacci = (INT n)INT:(
  REAL sqrt 5 = sqrt(5);
  REAL p = (1 + sqrt 5) / 2;
  REAL q = 1/p;
  ENTIER( (p**n + q**n) / sqrt 5 )
);

FOR i FROM 0 TO 16 WHILE
  print(whole(analytic fibonacci(i),0));
# WHILE # i /= 16 DO
  print(", ")
OD;
print(new line)