about summary refs log tree commit diff
path: root/doc/thalatta.5
blob: 2cc35b7809f5f513c952fbed94621d12322b98f1 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
.Dd April  5, 2026
.Dt THALATTA 5
.Os
.
.Sh NAME
.Nm thalatta
.Nd procedural graph description language
.
.Sh DESCRIPTION
.Nm
is a language used to generate attributed digraphs.
It is intended to be minimalist,
yet provides enough syntax for convenient graph construction.
.Nm
has C-like syntax,
but introduces some new features as well,
while removing unnecessary ones for graph context.
This manual shows only where
.Nm
differs from C.
.
.Ss Values
There are only 3 types in
.Nm :
arrays, integers, and nil.
.
.Pp
Arrays are constant:
a new one is allocated on operations such as assignment,
concatenation etc.
.
.Pp
Integers store not only user-defined numbers,
but also node and module identifiers used by an implementation.
These identifiers are used by the implementation
and should not be edited by the programmer.
.
.Pp
Nil type is the one that does not hold anything.
It can be used as a placeholder.
.Nm
has a predefined variable
.Dv nil
of the type of the same name.
.
.Ss Operations
.Nm
has operations very like in C,
excluding function calls,
structures,
and some others.
Instead introduces some new ones:
.Bl -tag -width Ds
.It Connecting
.Nm
is a graph description language.
The
.Ic <-
operator is used to connect a graph.
Its precedencence is like of an addition.
It creates a connection from right to left,
returning the left operand, so
.Bd -literal -offset indent -compact
a <- b <- c;
.Ed
connects both b and c to a,
not b to a and c to b.
.
.Pp
Connecting a node to an array
means connecting it all the cells from the array.
Connecting array to array is possible only if they are isomorphic,
i.e.,
they are of the same length,
and all subarrays are of the same length recursively,
if applicable.
.
.It Generation
.Nm
lacks array initializers like in C.
Instead,
there is a prefix operator
.Ic Bq Va expr ,
where
.Va expr
must be an integer.
This will allocate an array
of size
.Va expr .
For each array cell of depth n
there is a variable starting with @
followed by an nth letter of the alphabet
storing current depth's index.
.
.Pp
For example,
this code:
.Bd -literal -offset indent -compact
[2][3]node(@a, @b);
.Ed
.
.Pp
generates 4 nodes with properties as in binary count:
.Bd -literal -offset indent -compact
0 0 |
0 1 |
0 2 |
1 0 |
1 1 |
1 2 |
.Ed
.
.It Slicing
Besides simple indexing,
.Nm
has a postfix operator
.Ic Bq Va l Ic : Va r
that returns a slice of given array
from
.Va l
inclusive to
.Va r
non inclusive.
Both bounds are clamped
to the array limits.
.
.It Concatenation
The
.Ic ><
operator is used to concatenate 2 arrays.
Its precedence is like of a multiplication.
.
.It Exponentiation
Uses
.Ic **
operator,
is done before multiplication and right-associative.
.El
.
.Pp
.Nm
has also the prefix operator
.Ic len
to get an array length,
and the prefix operator
.Ic assert
aborting the execution
if its argument evaluates to zero,
and returning it otherwise.
.
.Ss Nodes
Nodes are created using the following syntax:
.Bd -literal -offset indent -compact
node(prop1, prop2);
.Ed
where properties are numbers.
This will return a number \(em
a unique node identifier.
.
.Ss Foreach
The
.Ic foreach
construct is used to iterate over elements of an array.
It recursively walks through its argument,
for each cell executing its body with variables
.Va @0
.Va @1
\&...
set just like the generation operator does.
In addition,
it sets the
.Va @
variable to the current element.
.
.Pp
This code ensures that every number in array
.Va arr
is greater than zero:
.Bd -literal -offset indent
foreach (arr) {
	assert(@ > 0);
}
.Ed
.
.Ss Modules
Instead of functions,
.Nm
has modules.
A module with parameters
.Ar a ,
.Ar b
can be defined like that:
.Bd -literal -offset indent
mod (a, b) { }
.Ed
It is possible to assign this
to a variable.
.
.Pp
Then,
to use this module later,
there is
.Ic with
statement,
that first evaluates the module
and then executes its body,
with parent scope set to the scope
of the module.
.
.Pp
This code tests whether the variable x is positive,
though in somewhat weird way to show the module usage:
.Bd -literal -offset indent
foo = mod(a) {
	b = a;
}

with foo(x) {
	assert(b > 0);
}
.Ed
.
.Sh SYNTAX
This is the syntax of
.Nm
expressed in ABNF:
.Bd -literal -indent offset
code = *(stmt)
stmt = comp / for / foreach / if / with / expr ";" / break / continue
continue = "continue" ";"
break = "break" ";"
with = "with" expr "(" [*(expr ",") expr] ")" stmt
if = "if" "(" expr ")" stmt ["else" stmt]
foreach = "foreach" "(" expr ")" stmt
for = "for" "(" [expr] ";" [expr] ";" [expr] ")" stmt
expr-assign-oper =/ "|=" / "^=" / "=" / ">>=" / "<<=" / "%="
expr-assign-oper =  "+=" / "-=" / "*=" / "/=" / "%=" / "&="
expr-assign      =  expr-cond [expr-assign-oper expr-assign]
expr-cond = expr-or ? expr : expr-cond
expr-pref = expr-post / ("assert" / "len" / "~" / "!" / "--" / "++") expr-pref
expr-post = expr-primary *("--" / "++" / "[" expr [":" expr] "]")
expr-mod = "mod" "(" [*(id ",") id] ")" comp
expr-node = "node" "(" [*(expr ",") expr] ")"
expr-primary = NUMBER / id / "nil" / expr-node / expr-mod / "(" expr ")"
comp = "{" *(stmt) "}"
expr = expr-assign
.Ed
.
.Sh EXAMPLES
This snippet creates a graph of a CLA adder:
.Bd -literal -offset indent
and = 0;
xor = 1;

add = mod(a, b, c)
{
	assert(len(a) == len(b));
	l = len(a);
	out = [l]node(xor);
	{
		p = [l]node(xor) <- a <- b;
		g = [l]node(and) <- a <- b;
		out <- p;

		foreach (out)
		{
			@ <- (node(and) <- p[0:@0] <- c);
			for (i = 0; i < @0; ++i)
				@ <- (node(and) <- p[i+1:@0] <- g[i]);
		}
	}
};

first = [8]node(xor, 0);
second = [8]node(xor, 1);
carry = node(xor, 2);
with add(first, second, carry) { }
.Ed
.
.Sh SEE ALSO
.Xr thac 1
.
.Rs
.%A B. W. Kernighan
.%A D. M. Ritchie
.%D 1978
.%B The C Programming Language
.Re
.
.Rs
.%A D. Crocker
.%A P. Overell
.%D January 2008
.%R RFC 5234
.%T Augmented BNF for Syntax Specifications: ABNF
.Re
.
.Sh AUTHORS
.An Nakidai Perumenei Aq Mt nakidai@disroot.org