aboutsummaryrefslogtreecommitdiff
path: root/doc/type-system.tex
diff options
context:
space:
mode:
Diffstat (limited to 'doc/type-system.tex')
-rw-r--r--doc/type-system.tex31
1 files changed, 18 insertions, 13 deletions
diff --git a/doc/type-system.tex b/doc/type-system.tex
index 3ae8a30..e1497be 100644
--- a/doc/type-system.tex
+++ b/doc/type-system.tex
@@ -1,5 +1,11 @@
\part{Type system}
+An Elna program consists of one or more source files, called \textbf{modules}.
+
+Each module can declare \textbf{types}, \textbf{global variables} and
+\textbf{procedures}, used by this module or exported to be used by other
+modules.
+
\begin{grammar}
<type> = <array-type>
\alt{} <pointer-type>
@@ -27,7 +33,6 @@
\end{grammar}
\begin{lstlisting}[caption=Example]
-program;
var
x: Int;
y: ^Int;
@@ -44,7 +49,6 @@ end.
\end{grammar}
\begin{lstlisting}[caption=Example]
-program;
var
array: [3]Int := [1, 2, 3];
begin
@@ -55,20 +59,23 @@ end.
\chapter{Procedure types}
\begin{grammar}
-<procedure-heading> = `proc' <identifier-definition> \\
- `(' [<field> \{`,' <field>\}] `)' <return-declaration>.
+<identifiers> = <identifier> \{`,' <identifier>\}.
+
+<parameter> = <identifiers> `:\@' <type>.
+
+<procedure-heading> = `(' [<parameter> \{`;' <parameter>\}] `)' <return-declaration>.
-<block> = <constant-part> <variable-part> <statement-part> `end'.
+<procedure-body> = <constant-part> <variable-part> <statement-part> `end'.
-<procedure-declaration> = <procedure-heading> `;' (block | `extern').
+<procedure-declaration> = `proc' <identifier-definition> <procedure-heading> \\
+ (<procedure-body> | `extern').
-<return-declaration> = [`->' `!\@' | `->' type].
+<return-declaration> = [`:\@' `!\@' | `:\@' type].
-<procedure-type> = `proc' `(' [<types>] `)' <return-declaration>.
+<procedure-type> = `proc' <procedure-heading>.
\end{grammar}
\begin{lstlisting}[caption=Example]
-program;
var
a: proc(Int) -> Int;
@@ -84,13 +91,12 @@ end.
\chapter{Records}
\begin{grammar}
-<field> = <identifier> `:\@' <type>.
+<field> = <identifiers> `:\@' <type>.
<record-type> = `record' [`(' <identifier> `)'] [<field> \{`;' <field>\}] `end'.
\end{grammar}
\begin{lstlisting}[caption=Example]
-program;
type
T = record
x: Int
@@ -111,11 +117,10 @@ end.
\chapter{Enumerations}
\begin{grammar}
-<enumeration-type> = `(' <identifier> \{`,' <identifier>\} `)'.
+<enumeration-type> = `(' <identifiers> `)'.
\end{grammar}
\begin{lstlisting}[caption=Example]
-program;
type
E = (one, two, three);
var