summaryrefslogtreecommitdiff
path: root/doc/type-system.tex
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-02-15 04:35:24 +0100
committerEugen Wissner <belka@caraus.de>2026-02-15 04:35:24 +0100
commit580bd7e8579f1de36d151249500de6601e43f4a1 (patch)
treee69d02bb786488aaf5cc6ba6671aa449f02223be /doc/type-system.tex
parent5959fbb5524bbeb05a96eb15aba59e961a3efcb7 (diff)
downloadelna-580bd7e8579f1de36d151249500de6601e43f4a1.tar.gz
Add documentation
Diffstat (limited to 'doc/type-system.tex')
-rw-r--r--doc/type-system.tex126
1 files changed, 126 insertions, 0 deletions
diff --git a/doc/type-system.tex b/doc/type-system.tex
new file mode 100644
index 0000000..3ae8a30
--- /dev/null
+++ b/doc/type-system.tex
@@ -0,0 +1,126 @@
+\part{Type system}
+
+\begin{grammar}
+<type> = <array-type>
+ \alt{} <pointer-type>
+ \alt{} <record-type>
+ \alt{} <enumeration-type>
+ \alt{} <procedure-type>
+ \alt{} <identifier>.
+\end{grammar}
+
+\chapter{Primitive types}
+
+\begin{itemize}
+ \item Pointer
+ \item Word
+ \item Int
+ \item Bool
+ \item String
+ \item Char
+\end{itemize}
+
+\chapter{Pointer types}
+
+\begin{grammar}
+<pointer-type> = `^' <type>.
+\end{grammar}
+
+\begin{lstlisting}[caption=Example]
+program;
+var
+ x: Int;
+ y: ^Int;
+begin
+ y := @x;
+ y^ := 0
+end.
+\end{lstlisting}
+
+\chapter{Static array}
+
+\begin{grammar}
+<array-type> = `[' <expression> `]' <type>.
+\end{grammar}
+
+\begin{lstlisting}[caption=Example]
+program;
+var
+ array: [3]Int := [1, 2, 3];
+begin
+ array[1] := array[2]
+end.
+\end{lstlisting}
+
+\chapter{Procedure types}
+
+\begin{grammar}
+<procedure-heading> = `proc' <identifier-definition> \\
+ `(' [<field> \{`,' <field>\}] `)' <return-declaration>.
+
+<block> = <constant-part> <variable-part> <statement-part> `end'.
+
+<procedure-declaration> = <procedure-heading> `;' (block | `extern').
+
+<return-declaration> = [`->' `!\@' | `->' type].
+
+<procedure-type> = `proc' `(' [<types>] `)' <return-declaration>.
+\end{grammar}
+
+\begin{lstlisting}[caption=Example]
+program;
+var
+ a: proc(Int) -> Int;
+
+proc f(x: Int) -> Int;
+end;
+
+begin
+ a := f;
+ a(0)
+end.
+\end{lstlisting}
+
+\chapter{Records}
+
+\begin{grammar}
+<field> = <identifier> `:\@' <type>.
+
+<record-type> = `record' [`(' <identifier> `)'] [<field> \{`;' <field>\}] `end'.
+\end{grammar}
+
+\begin{lstlisting}[caption=Example]
+program;
+type
+ T = record
+ x: Int
+ end;
+ U = record(T)
+ y: Int;
+ z: Int
+ end;
+
+var
+ u: U;
+begin
+ u := U(0, 1, 2);
+ u.x := 3
+end.
+\end{lstlisting}
+
+\chapter{Enumerations}
+
+\begin{grammar}
+<enumeration-type> = `(' <identifier> \{`,' <identifier>\} `)'.
+\end{grammar}
+
+\begin{lstlisting}[caption=Example]
+program;
+type
+ E = (one, two, three);
+var
+ e: E;
+begin
+ e := E.one
+end.
+\end{lstlisting}