\documentclass{scrreprt} \usepackage[T1]{fontenc} \usepackage{tabularx} \usepackage{booktabs} \usepackage{listings} \usepackage{syntax} \title{The programming language Elna} \begin{document} \maketitle \tableofcontents \chapter{Introduction} Elna is a simple, imperative, low-level programming language. It is intendet to accompany other languages in the areas, where a high-level language doesn't fit well. It is also supposed to be an intermediate representation for a such high-level hypothetical programming language. \part{Language} \chapter{Expressions} The expression \verb|@r.field| includes 3 expressions: \begin{enumerate} \item Variable expression \verb|r|. \item Field access \verb|(r).field|. \item Address taking \verb|@(r.field)|. \end{enumerate} The expression is evaluated in the above order. The postfix expressions like field access have higher precedence than prefix operators. \section{Binary expressions} \begin{table} \centering \begin{tabularx}{0.8\textwidth}{% l >{\centering\arraybackslash}X >{\raggedright\arraybackslash}X } \textbf{Precedence} & \textbf{Operator} & \textbf{Description}\\ \toprule 1 & $* \quad / \quad \%$ & Multiplication, division and remainder.\\ \midrule 2 & $+ \quad -$ & Addition and subtraction.\\ \midrule 3 & $<< \quad >>$ & Left and right shifts.\\ \midrule 4 & $= \quad <> \quad > \quad < \quad <= \quad >=$ & Relational operators.\\ \midrule 5 & $or \quad xor \quad \&$ & Logical operators.\\ \bottomrule \end{tabularx} \caption{Operator precedence} \end{table} \section{Unary expressions} Unary expressions are expressions with a prefix operator followed by one operand. \verb|@| (\textit{at sign}) takes the address of its operand. The operand expression should be addressable. \verb|-| (\textit{minus}) negates a numeric value. \verb|~| (\textit{tilde}) applied on a boolean acts as logical not. Applied on a numeric – as bitwise not. \chapter{Conditional statements} \chapter{Loop statements} \part{Type system} \begin{grammar} = \alt{} \alt{} \alt{} \alt{} \alt{} . \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} = `^' . \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} = `[' `]' . \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} = `proc' \\ `(' [ \{`,' \}] `)' . = `end'. = `;' (block | `extern'). = [`->' `!\@' | `->' type]. = `proc' `(' [] `)' . \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} = `:\@' . = `record' [`(' `)'] [ \{`;' \}] `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} = `(' \{`,' \} `)'. \end{grammar} \begin{lstlisting}[caption=Example] program; type E = (one, two, three); var e: E; begin e := E.one end. \end{lstlisting} \chapter{Type operations} \chapter{Cast} \begin{grammar} = `cast' `(' `:\@' `)'. \end{grammar} The type of an object can be reinterpreted with a cast expression: \\ \verb|cast(object: Type)|. \chapter{Traits} \begin{grammar} = `#' . = `(' [] `)'. \end{grammar} Traits allow to query some information about the types, like their size or field offset or alignment. Calling a trait looks like a procedure call but traits names start with a \verb|#| and their arguments are type expressions and not value expressions. Supported compiler traits: \begin{itemize} \item \verb|#size(T)| queries type size. \item \verb|#align(T)| queries type alignment. \item \verb|#offset(T, F)| queries the offset of the field \verb|F| in the record \verb|T|. \end{itemize} \part{Appendix} \chapter{Syntax} \begin{grammar} = `A' | `B' | … | `Z' | `a' | `b' | … | `z' | `\_'. = `1' | `2' | `3' | `4' | `5' | `6' | `7' | `8' | `9'. = `0' | . = | `A' | `B' | … | `F' | `a' | `b' | … | `f'. = `0' | `1'. = `\\x' . = `\\' \\ (`n' | `a' | `b' | `t' | `f' | `r' | `v' | `\\' | `\textquotesingle' | `\textquotedbl' | `?\@' | `0'). = \enspace? a printable ASCII character\space?. = | | . = \{ | \}. = [`*']. = `#' . = `0' | \{\}. = `u' \alt{} `0' (`X' | `x') \{\} \alt{} `0' (`B' | `b') \{\}. = `.\@' \{\} \alt{} \} `e' [`+' | `-'] \{\}. = `\textquotedbl' \{\} `\textquotedbl'. = `\textquotesingle' `\textquotesingle'. = | | \alt{} | \alt{} `true' | `false' | `nil'. = `(' [] `)'. = `cast' `(' `:\@' `)'. = `(' [] `)'. = `=' | `<>' | `<' | `>' | `<=' | `>='. = `*' | `/' | `\%'. = `+' | `-'. = `<<' | `>>'. = `@' | `~' | `-'. = `[' `]' | `.\@' | `^'. = `:\@' . = | . = \alt{} \alt{} \alt{} \alt{} \alt{} `(' `)'. = | . = \{ \}. = \{ \}. = \{ \}. = \{ \}. = \{`&' \}. = \{(`or' | `xor') \}. = \{`,' \}. = \{`,' \}. = \{`,' \}. = \{`;' \}. = []. = [`->' `!\@' | `->' type]. = `:\@' . = `[' `]' . = `^' . = `record' [`(' `)'] [ \{`;' \}] `end'. = `(' \{`,' \} `)'. = `proc' `(' [] `)' . = \alt{} \alt{} \alt{} \alt{} \alt{} . = `:=' . = `if' `then' \\ \{`elsif' `then' \} \\ {[`else' ]} `end'. = `while' `do' \\ \{`elsif' `do' \} `end'. = `defer' `end'. = `case' `of' \{`|' case\} \\ {[`else' ]} `end'. = `.\@' . = `goto' . = | | | | | | | | . = [`begin' \alt{} `return' \alt{} `begin' `;' `return' ]. = `:=' . = [`const' \{ `;'\}]. = `:\@' \\ {[`:=' ( | `extern')]}. = [`var' \{ `;'\}]. = `=' . = [`type' \{ `;'\}]. = \{`.\@' \}. = [`import' \{import-declaration `;'\}]. = `proc' \\ `(' [ \{`,' \}] `)' . = `end'. = `;' (block | `extern'). = \\ \\ \{ `;'\}. = `program' `;' `end' `.\@' \alt{} `module' `;' `end' `.\@'. \end{grammar} \end{document}