(datatype declaration
Type : type; Variables : (list symbol);
=============================================
[declare Type Variables] : declaration;
Type : type; Variable : symbol; Dim : integer;
===================================================
[declare [vector Type] Variable Dim] : declaration;)
(defcc <declaration>
{(list string) ==> declaration}
<ws> <type> <space> <ws> <variables> := [declare <type> <variables>];
<ws> <type> <space> <ws> <variable> <ws> <dim>
:= [declare [vector <type>] <variable> <dim>];)
(datatype integer
if (integer? N)
____________
N : integer;
if (element? Op [+ - *])
M : integer; N : integer;
___________________________
(Op M N) : integer;
N : integer;
_____________________
N : number;)
(defcc <dim>
{(list string) ==> integer}
"[" <ws> <int> <ws> "]" := <int>;)
(defcc <int>
{(list string) ==> integer}
<int-h> := (compute-int <int-h>);)
(defcc <int-h>
{(list string) ==> (list integer)}
<numeric> <int-h> := [(digit <numeric>) | <int-h>];
<numeric> := [(digit <numeric>)];)
(defcc <numeric>
{(list string) ==> string}
X := X where (element? X ["0" "1" "2""3""4""5" "6" "7" "8" "9"]);)
(define digit
{string --> integer}
"0" -> 0
"1" -> 1
"2" -> 2
"3" -> 3
"4" -> 4
"5" -> 5
"6" -> 6
"7" -> 7
"8" -> 8
"9" -> 9)
(define compute-int
{(list integer) --> integer}
[] -> 0
[N | Ns] -> (+ (* N (expt 10 (intlength Ns))) (compute-int Ns)))
(define expt
{integer --> integer --> integer}
_ 0 -> 1
M N -> (* M (expt M (- N 1))))
(define intlength
{(list A) --> integer}
[] -> 0
[_ | Y] -> (+ 1 (intlength Y)))
(datatype type
if (element? T [int char float])
________________________
T : type;)
(defcc <type>
{(list string) ==> type}
($ int) := int;
($ char) := char;
($ float) := float;)
(defcc <variables>
{(list string) ==> (list symbol)}
<variable> <ws> "," <ws> <variables> := [<variable> | <variables>];
<variable> := [<variable>];)
(defcc <variable>
{(list string) ==> symbol}
<alphanumeric> := (string->symbol <alphanumeric>);)
(defcc <alphanumeric>
{(list string) ==> string}
<alpha> <alphanumeric-h> := (@s <alpha> <alphanumeric-h>);)
(defcc <alphanumeric-h>
{(list string) ==> string}
<alpha> <alphanumeric-h> := (@s <alpha> <alphanumeric-h>);
<numeric> <alphanumeric-h> := (@s <numeric> <alphanumeric-h>);
<e> := "";)
(defcc <alpha>
{(list string) ==> string}
"a" := "a"; "A" := "A"; "b" := "b";"B" := "B";
"c" := "c";"C" :="C";"d" := "d";"D" := "D";
"e" := "e";"E" := "E";"f" := "f";"F" := "F";
"g" := "g"; "G" := "G";"h" := "h"; "H" := "H";
"i" := "i";"I" := "I";"j" := "j";"J" := "J";
"k" := "k"; "K" := "K";"l" := "l";"L" := "L";
"m" := "m"; "M" := "M"; "n" := "n";"N" := "N";
"o" := "o";"O" := "O"; "p" := "p";"P" := "P";
"q" := "q";"Q" :="Q"; "r" := "r";"R" := "R";
"s" := "s";"S" := "S"; "t" := "t";"T" := "T";
"u" := "u"; "U" := "U"; "v" := "v"; "V" := "V";
"w" := "w";"W" := "W"; "x" := "x";"X" := "X";
"y" := "y"; "Y" := "Y"; "z" := "z";"Z" := "Z";
"_" := "_";)
(defcc <numeric>
{(list string) ==> string}
X := X where (element? X ["0" "1" "2""3""4""5""6""7""8""9"]);)
(defcc <ws>
{(list string) ==> A}
<comment> <ws> := skip!;
<space> <ws> := skip!;
<tab> <ws> := skip!;
<newline> <ws> := skip!;
<e> := skip!;)
(defcc <space>
{(list string) ==> A}
X := skip! where (= (string->n X) 32);)
(defcc <tab>
{(list string) ==> A}
X := skip! where (= (string->n X) 9);)
(defcc <newline>
{(list string) ==> A}
X := skip! where (element? (string->n X) [10 13]);)
(defcc <comment>
{(list string) ==> A}
"/" "*" <comment-body> := skip!;)
(defcc <comment-body>
{(list string) ==> A}
"/" "*" := skip!;
_ <comment-body> := skip!;)