S-algol is a programming language created in 1979 by Ron Morrison and Tony Davie.
#1224on PLDB | 45Years Old |
S-algol (St Andrews Algol) is a computer programming language derivative of ALGOL 60 developed at the University of St Andrews in 1979 by Ron Morrison and Tony Davie. The language is a modification of ALGOL to contain orthogonal data types that Morrison created for his PhD thesis. Morrison would go on to become professor at the university and head of the department of computer science. Read more on Wikipedia...
write "Hello World"
?
! Comments are introduced by an exclamation point and continue until end of line.
! The let keyword introduces declarations of constants and variables
! Identifiers start with an alphabetic character followed by alphanumeric characters or the full stop (.)
! An initial value must be given, and this determines the data type of declaration
let width := 10 ! := sets the value of a variable, this is an int
let animal := "dog" ! type string
let x := -7 ; let y := x + x ! ; separates clauses, needed only if there are two or more clauses on a line
let n.a = 6.022e+23 ! = is used to set the value of a constant, this is a cfloat (constant float)
! if and case can have values and be used in expressions
let no.of.lives := if animal = "cat" then 9 else 1
! Sieve of Eratosthenes
write "Find primes up to n = ?"
let n = readi ! constant values can be set during the program run
let p = vector 2::n of true ! vector of bool with bounds 2 to n
for i = 2 to truncate(sqrt(n)) do ! for indexes are constants so they use = rather than :=
if p(i) do ! vector dereference uses parens like a procedure call
for j = 2 * i to n by i do
p(j) := false
for i = 2 to n do
if p(i) do write i, "'n" ! 'n in a literal string is a newline
! structure (record) type for a binary tree of cstrings
! the pntr data type can point to a structure of any type, type checking is done at runtime
structure tree.node(cstring name ; pntr left, right)
! inserts a new string into the binary tree head
procedure insert.tree(cpntr head ; cstring new -> pntr)
! the case clause ends with a mandatory default option, use default : {} if it is not needed
case true of
head = nil : tree.node(new, nil, nil)
new < head(name) : { head(left) := insert.tree(head(left), new) ; head }
new > head(name) : { head(right) := insert.tree(head(right), new) ; head }
default : head
procedure print.tree(cpntr head)
if head ~= nil do ! ~= is the not equals operator
begin
print.tree(head(left))
write head(name), "'n"
print.tree(head(right))
end
let fruit := nil
fruit := insert.tree(fruit, "banana")
fruit := insert.tree(fruit, "kiwi")
fruit := insert.tree(fruit, "apple")
fruit := insert.tree(fruit, "peach")
print.tree(fruit) ! print in sorted order
! The end of the S-algol program is indicated by ?
?
Feature | Supported | Example | Token |
---|---|---|---|
Booleans | ✓ | true false | |
Strings | ✓ | "Hello world" | " |
Print() Debugging | ✓ | write | |
Comments | ✓ | ! A comment | |
Line Comments | ✓ | ! A comment | ! |
Semantic Indentation | X |