1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
\section{Program Structure}
A program consists of the header followed by a list of bindings.
\fragment{
\BNF{
\Rule{\MC{program}}{\MC{intro} \oneplus{\MC{binding}}}
\Rule{\MC{intro}}{\CD{module} \MC{identifier}}
\Or{\MC{identifier} \MC{identifier}}
\Or{\MC{shebang}}
}
}
The header is either a module declaration, giving the module name, a
program declaration, or a \CD{\#!} path.
\begin{itemize}
\item If a module declaration, it will be compiled as a module,
generating a \texttt{.o} file containing code and a \texttt{.ki}
file containing interface details.
\item If a program declaration, the first identifier gives the name of the
file containing startup code (this is often one of \CD{program},
\CD{cgi} or \CD{webapp}), the second gives the root name of the
output file. See section \ref{sect:progtype}.
\item If a \texttt{\#!} path, the file is assumed to be a \CD{program}
and will be executed immediately after compilation --- this allows
\Kaya{} to be used for scripting.
\end{itemize}
Bindings contain the body of the program. They may be used to import
other modules; they may be functions, data declarations (already seen
in section \ref{usertypes}, global variable declarations or foreign
function declarations. They may also contain compiler directives.
\fragment{
\BNF{
\Rule{\MC{binding}}{\MC{import}}
\Or{\MC{function}}
\Or{\MC{data\_decl}}
\Or{\MC{global\_block}}
\Or{\MC{foreign\_block}}
\Or{\MC{directive}}
}
}
|