A Dino program is simply a sequence of statements. There is a special declaration useful for writing programs consisting of several files or for making Dino packages. This is the include-declaration. Before execution of any statements all include-declarations are replaced by files whose base names are given by the strings. It is made recursively, i.e. the files themselves can contain other include-declarations. There should be no infinite recursion in this. If + is present in the include-declaration, the file is inserted in any case. Without + the file is inserted only if it has been yet not inserted into the block of the declaration.
Program = StmtList
IncludeDeclaration = include ["+"] STRING ";"
Examples:
The following program outputs the first 24 Fibonachi numbers:
// Recursive function to compute Fibonacci numbers
func fibonacci (n)
{
if (n <= 1) return 1;
return (fibonacci(n-1) + fibonacci(n-2));
}
var i, fibnum;
fibnum = 0;
for (i = 0; i <= 24; i++)
{
fibnum = fibonacci(i);
putln (i @ " " @ fibnum);
}
The following program outputs the number of prime numbers less than 8190:
var i, prime, k, count, flags;
var final SieveSize = 8190;
flags = [SieveSize + 1 : 0];
count = 0;
for (i = 0; i <= SieveSize; i++)
flags[i] = 1;
for (i = 0; i <= SieveSize; i++)
if (flags[i])
{
prime = i + i + 3;
k = i + prime;
for (;1;;)
{
if (k > SieveSize)
break;
flags[k] = 0;
k += prime;
}
count++;
}
println (count);
The following program outputs the number of occurrences of different numbers and identifiers in stdin:
var i, key, voc = {};
for (;;)
try {
var ln, a;
ln = getln ();
if (ln == "")
continue;
a = split (ln, "[^[:alnum:]]");
for (i = 0; i < #a; i++)
voc {a[i]} = (a[i] in voc ? voc {a[i]} + 1 : 1);
} catch (invcalls.eof) {
break;
}
func comp (el1, el2) {
return cmpv (tolower (el1), tolower (el2));
}
key = sort (keys (voc), comp);
for (i = 0; i < #key; i++)
putln (key[i], " : ", voc{key[i]});
The following program uses the Dino package mpi
:
include "mpi";
var mpi1, mpi2;
mpi1 = mpis.from_string(50, "1000000000000000000000000000000000000");
mpi2 = mpis.from_string(50, "5000000000000000000000000000000000000");
putln (mpis.to_string (mpis.add (mpi1, mpi2)));