-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.html
More file actions
246 lines (210 loc) · 5.75 KB
/
Copy pathsyntax.html
File metadata and controls
246 lines (210 loc) · 5.75 KB
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
<html lang="en" data-bs-theme="dark"><head>
<meta charset="utf-8">
<meta name="description" content="Wee programming language syntax.">
<meta name="author" content="Elucian Moise">
<meta name="keywords" content="sage, code, wee, language, syntax, tutorial">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Website title -->
<title>Wee Syntax</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<!-- Icon -->
<link rel="icon" type="image/png" href="../images/favicon.ico">
<!-- Prism Highlighter -->
<link rel="stylesheet" href="../prism.css">
<script src="../prism.js"></script>
<!-- custom css -->
<link rel="stylesheet" href="../sage.css">
</head>
<body>
<div class="container">
<!-- header -->
<div class="row">
<div class="col">
<a href="https://sagecode.net"><img src="../images/sage-logo.svg" alt="Sage-Code Laboratory" height="80"/></a>
</div>
<div class="col bottom-right">
<a href="index.html#lang-index" rel="nofollow">index</a><--
</div>
</div><hr>
<h1>Wee Syntax</h1>
<div class="alert alert-secondary shadow-sm">
Wee is a low level, minimalistic programming language design by Sage-Code.
</div>
<!-- work in progress-->
<hr>
<h2>Wee keywords</h2>
<p>Wee uses 26 English reserved keywords:</p>
<pre class="language-wee">
if, is, in, or, go, do
use, new, let, get, put, say, def, out, log
case, spin, more, node, else, done, back, share, clear
run, loop, over
</pre>
<h4>Page bookmarks</h4>
<ul>
<li>input/output</li>
<li>declaration </li>
<li>expression </li>
<li>conditional </li>
<li>repetition </li>
<li>subroutine </li>
</ul>
<h2>Import</h2>
<p>To find public members in other files: Wee create this statement:
use folder.name/file_name.wee
...
Public members start with capital letter.
</p>
<h2>IO</h2>
For input output wee uses console and 3 statements:
<pre class="language-wee">
out ;write something to console
say ;write something to console and new line
ask ;print something and wait for input
</pre>
<h2>Declaration</h2>
<p>
Wee is typeless, or more precisely has one data type: the computer word. Sometimes this represent a computer address that has to be dereferenced. Capacity of word is 16 bit, 32 bit or 64 bit depending on the operating system.
syntax
</p>
<pre class="language-wee">
new identifier : constant ; using constant literal
new identifier : expression ; using expression
** define several identifiers with same initial value
new identifier, identifier,... :expression
example
new v : 0
new x,y,z : 10
</pre>
<p>
Note:
<ul>
<li>Wee data types are aligned to memory address: 00000000-FFFFFFFF</li>
<li>Wee core library can not handle decimal numbers nor division</li>
</ul>
</p>
<h2>Expression</h2>
<p>Expressions can be used for assign operator : or modifiers: +:, -:</p>
<pre class="language-wee">
new v : 10 ;number
new s : 5 ;number
let v +: 1 ;make v = 11
let v -: 1 ;make v = 10
let s : v + s; copy v = 15 to s
</pre>
<h4>Notes:</h4>
<ul>
<li>Operator "=" is used as logic operator;</li>
<li>Types are defined using type inference;</li>
</ul>
<h2>Pointer</h2>
<p>Wee is using pointers. You can dereference a pointer using symbol "@"</p>
<pre class="language-wee">
new v : 10 ; define a new variable
new p : @v ; define a reference to v
say p ; expected 10
** using assign ":"
let v : 2; change underline value of p
say ?p ; expected 2
** reset pointer
new o : 4
let p : @o ; reset
say p ; expected 4
say v ; expected 2 (unmodified)
</pre>
<h2>Console</h2>
<p>The console application accept and print characters:</p>
<pre class="language-wee">
ask i : "enter any char"
say i ; will print the char
</pre>
<h2>Conditional</h2>
<p>Conditional if statement has a postfix form:
<pre class="language-wee">
statement if condition
</pre>
<p>Ternary expression;</p>
<pre class="language-wee">
let new_variable : (value if condition,
value if condition,
value);
</pre>
<h2>Decision</h2>
A decision is using one condition to create a fork:
<pre class="language-wee">
when condition do
** true
else
** false
done
</pre>
<h2>Case</h2>
A case is a multi-path selector that is using multiple conditions:
<pre class="language-wee">
case condition do
** first path
...
case condition do
** second path
...
else
** alternative path
...
done
</pre>
<h2>Repetition</h2>
Repetitive block is realized using a do block:
<pre class="language-wee">
**repetitive block
do
...
loop if (condition)
...
stop if (condition)
more
</pre>
<h4>note</h4>
<ul>
<li>Do block can not be nested inside another do block;
<li>Statement loop is optional but statement over is mandatory,
</ul>
<h2>Subroutine</h2>
Node is a named block of code with local context similar to a subroutine:
<pre class="language-wee">
node name:
do
get a, b, c : 0
put a + b + c
done
</pre>
<h2>Private context</h2>
A private context is an anonymous block of code used to run a node;
<pre class="language-wee">
share
new r : 0
put a : 5, b : 10, c : 20
run node_name
pop r
say r
clear
</pre>
<p>Using outer variables is possible in private context.</p>
<pre class="language-wee">
new r: 0
share
put a: 5, b: 10, c: 20
run node_name
pop r
clear -- a, b, c
say r -- a+b+c = 35
</pre>
<p><b>Read next:</b>
<a href="collections.html">Collections</a></p>
<!-- Footer -->
<footer class="footer">
<div class="footer-copyright text-center"></div>
</footer>
</div>
</body>
</html>