summaryrefslogtreecommitdiff
path: root/doc/language.tex
blob: a18dac8b053a4a142a0a1f8f85c6cddedd5ab057 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
\part{Language}

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.

Each procedure can get some input and produce an output as a result of
executing a \textbf{statement block}, a list, where each \textbf{statement}
is executed in the order it appears in the block.

Statement components are other statement blocks and \textbf{expressions},
where a statement has control over the evaluation of its components.
Statements can also modify the state of the procedure or the program by
mutating variables.

Most simple expressions are identifiers referencing program's symbols and
literals. These atomic expressions can be combined to more complex expressions
by applying various operations to one or more expressions.

\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}