about summary refs log tree commit diff
path: root/ccl.7
blob: 254fe0459b0da085ad7d8d186d7e3ed1815f0862 (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
.Dd March 25, 2025
.Dt CCL 7
.Os
.
.Sh NAME
.Nm ccl
.Nd cool char lang
.
.Sh DESCRIPTION
.Nm
is a brainfuck-inspired language,
Unlike in brainfuck,
though,
.Nm
manipulates the stack,
not the array.
Also,
each cell in
.Nm
is a 16 bit signed integer
with overflow allowed.
Stack doesn't have size limitations,
though ram in your pc is still limited.
All names in
.Nm
are limited to 1 character.
.
.Pp
.Nm
has variables.
There're 2 sets of variables:
global and local ones.
Local variables
are different for each
.Sy procedure .
.
.Pp
As was stated before,
there are
procedures.
Their names are stored
separately from variables',
so you can store
both variable and function
with the same name.
Procedures are defined at runtime,
and it's possible
to overwrite them.
.
.Pp
There're 3 types of instruction.
First type is an instruction
without any argument.
Its name can be simply
put in the code.
Second is an instruction
with an argument.
Arguments are mandatory,
meaning you cannot omit them.
Though,
there's special variable
with the name
.Ic _ ,
but not every instruction
will accept it.
Third type is a block.
It's a pair of characters
that stores some code
between them.
Also,
block accepts an argument
on the left of left character.
.
.Pp
Instructions
that work with the stack
will throw
an uncatchable error
if stack is too small.
.
.Pp
Comments are done using
.Ic /
character.
They end on the end of line.
.
.Pp
The instructions are as follows:
.Bl -tag -width Ds
.It Ic ^
Takes no parameters.
Pushes a new cell on the stack
with the value 0.
.
.It Ic +
Takes no parameters.
Increments last cell
on the stack.
.
.It Ic -
Takes no parameters.
Decrements last cell
on the stack.
.
.It Ic *
Takes no parameters.
Pops last cell
and then adds its value
to a new last
storing the result here.
.
.It Ic ~
Takes no parameters.
Pops last cell
and then subtracts its value
from a new last
storing the result here.
.
.It Ic #
Takes no parameters.
If called from a loop,
exits it
.Po
like
.Ql break
.Pc .
If called from a procedure,
exits it
.Pc
like
.Ql return
.Pc .
Otherwise
.Pq meaning called from outside of anything
exits the program.
.
.It Ic \&:
Takes no parameters.
If called from a loop,
skips current iteration,
acting like a
.Ql continue .
.
.It Ic %
Takes a parameter.
Accepts
.Ic _ .
Reverses last n
variables on the stack,
where n is a value of
a provided variable
or size of the stack if
.Ic _
was provided.
Variable with a given name
must exist.
.
.It Ic =
Takes a parameter.
Accepts
.Ic _ .
Pops last cell
and then assigns
.Pq possibly overriding
its value
to a given variable,
or just pops if
.Ic _
was provided.
.
.It Ic \&!
Takes a parameter.
Doesn't accept
.Ic _ .
Deletes variable
of a given name.
Prefers local ones first.
Variable with a given name
msut exist.
.
.It Ic $
Takes a parameter.
Doesn't accept
.Ic _ .
Pushes given variable's value
on the stuck.
Variable with a given name
must exist.
.
.It Ic &
Takes a parameter.
Doesn't accept
.Ic _ .
Creates a local variable
with a given name
assigning 0 to it.
If variable with a given name
exists,
overrides it
to be 0.
Note that every operation
prefers local variables
first.
.
.It Ic <
Takes a parameter,
Doesn't accept
.Ic _ .
Prints the value
of a given variable
as an
.Xr ascii 7
character.
Variable with a given name
must exist.
.
.It Ic >
Takes a parameter.
Doesn't accept
.Ic _ .
Reads the character
from the console,
writing its value
to a variable.
Variable with a given name
must exist.
.
.It Ic @
Takes a parameter.
Doesn't accept
.Ic _ .
Calls a procedure with a given name.
Procedure with a given name
must exist.
.
.It Ic { }
Doesn't accept
.Ic _ .
Defines a procedure
with a given name.
May override.
.
.It Ic \&( \&)
Accepts
.Ic _ .
Enters a condtional loop.
Continues working
until given variable
is less then or equal to 0.
Variable with a given name
must exist.
If a parameter is
.Ic _ ,
then acts as infinite loop.
.
.It Ic \&[ \&]
Repeats its body n times
where n is a value of
a variable with a given name.
Variable with a given name
must exist.
.
.It Ic \&? \&;
Executes its body
if a variable with a given name
is equal to the last cell
on the stack.
Variable with a given name
must exist.
.El
.
.Sh SEE ALSO
.Xr ascii 7 ,
.Xr 3cl 1 ,
.Lk https://github.com/holy-8/cool_char_lang Original implementation
.
.Sh AUTHORS
Original implementation is written by
.Lk https://github.com/holy-8 holy8 ,
slightly patched and rewritten in
.Xr mdoc 7
by
.An Nakidai Perumenei Aq Mt nakidai@disroot.org