-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
445 lines (433 loc) · 16.2 KB
/
index.html
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!DOCTYPE html>
<html>
<head>
<title>jsr Programming Language Documentation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>JSR</h1>
<p>
JSR stands for javascript reverse. It is a programming language that is designed for fun. <b>It is not
absulatlly a
reverse
version of javascript</b>. It is a complicated language. It is compiled to javascript. You have to write
this
programme
in a file with .jsr extension but from the bottom. That means the last line of your code will be the first line
of your file. And the first line of your code will be the last line of your file.
</p>
<p>
<imp>
<b>Warning:</b> Don't miss any semicolon. If you miss any semicolon, you will get an error.
<b>Warning:</b> Don't use any keyword as a variable name. If you use any keyword as a variable name, you
will get an error.
<b>Warning:</b> Must include std to start your code. If you don't include std, you will get an
error.<code>#include<std></code>
</imp>
</p>
<p>
Problem is not end here. The blocks of this code will run from top to bottom, like other programmes. But the
lines of a block will run from bottom to top. That means the last line of a block will run first and the first
line of a block will run last.
</p>
<h2>Confused?</h2>
<p>
Let's see an example. Suppose you want to print "Hello, world!" in the console. In javascript, you will write
this code:
<pre><code>console.log("Hello, world!");</code></pre>
But in jsr, you have to write this code:
<pre><code>
print("Hello, world!");
#include<std>
</code></pre>
This was prity easy, right!
</p>
<p>
But now, let's see a complex example. Suppose you want to print the sum of two numbers. In javascript, you will
write
this code:
<pre><code>
let a = 10;
let b = 20;
let c = 0;
console.log(c); // 0
function sum(a, b) {
c += a + b;
return c;
}
console.log(sum(a, b));// 30
</code></pre>
But in jsr, you have to write this code:
<pre><code>
print(c); /* 0 */
velt c = 0;
velt b = 20;
velt a = 10;
print(c); /*Error : Cannot access 'c' before initialization*/
#include<std>
function sum1(a, b) {
return c;
c += a;
c += a + b;
}
function sum2(a, b) {
c += a + b;
return c;
}
print(sum1(a, b)); /* 40 */
print(sum2(a, b)); /* undefined */
</code></pre>
This was a little bit complex, right!
</p>
<p>
You can use any text editor to write this code. But you have to compile this code <a
href="./console.html">here</a>.
</p>
<h2>Variables</h2>
<p>
In jsr, you can declare variables using the following keywords:
<ul>
<li><code>velt</code> <span>Used to declare a mutable variable.</span></li>
<li><code>velc</code> <span>Used to declare a constant variable.</span></li>
</ul>
Example:
<pre><code>velt myVariable = 42;
const PI = 3.14;</code></pre>
</p>
<h2>Importing Modules</h2>
<p>
To import modules in jsr, use the <code>include</code> keyword.
Example:
<pre><code>#include<myModule></code></pre>
</p>
<h2>Output</h2>
<p>
To print output to the console, use the <code>print()</code> function.
Example:
<pre><code>print("Hello, world!");</code></pre>
</p>
<h2>Input</h2>
<p>
To read input from the user, use the <code>input()</code> function.
Example:
<pre><code>velt name = input("Enter your name:");</code></pre>
</p>
<h2>Exit</h2>
<p>
To exit the program, use the <code>exit()</code> function.
Example:
<pre><code>exit();</code></pre>
</p>
<h2>Clearing the Console</h2>
<p>
To clear the console, use the <code>clear()</code> function.
Example:
<pre><code>clear();</code></pre>
</p>
<h2>Type Conversion</h2>
<p>
To convert values to specific types, use the following functions:
<ul>
<li><code>num()</code> <span>Converts a value to a number.</span></li>
<li><code>str()</code> <span>Converts a value to a string.</span></li>
</ul>
Example:
<pre><code>velt number = num("42");
velt string = str(3.14);</code></pre>
</p>
<h2>Operators</h2>
<p>
In jsr, you can use the following operators:
<ol>
<li><code>+</code> <span>Addition operator.</span></li>
<li><code>-</code> <span>Subtraction operator.</span></li>
<li><code>*</code> <span>Multiplication operator.</span></li>
<li><code>/</code> <span>Division operator.</span></li>
<li><code>%</code> <span>Modulus operator.</span></li>
<li><code>**</code> <span>Exponentiation operator.</span></li>
<li><code>++</code> <span>Increment operator.</span></li>
<li><code>--</code> <span>Decrement operator.</span></li>
<li><code>+=</code> <span>Addition assignment operator.</span></li>
<li><code>-=</code> <span>Subtraction assignment operator.</span></li>
<li><code>*=</code> <span>Multiplication assignment operator.</span></li>
<li><code>/=</code> <span>Division assignment operator.</span></li>
<li><code>%=</code> <span>Modulus assignment operator.</span></li>
<li class="new"><code>=+</code> <span>Addition before assignment operator.</span></li>
<li class="new"><code>=-</code> <span>Subtraction before assignment operator.</span></li>
<li class="new"><code>=*</code> <span>Multiplication before assignment operator.</span></li>
<li class="new"><code>=/</code> <span>Division before assignment operator.</span></li>
<li class="new"><code>=%</code> <span>Modulus before assignment operator.</span></li>
<li><code>**=</code> <span>Exponentiation assignment operator.</span></li>
<li><code>==</code> <span>Equality operator.</span></li>
<li><code>!=</code> <span>Inequality operator.</span></li>
<li><code>===</code> <span>Strict equality operator.</span></li>
<li><code>!==</code> <span>Strict inequality operator.</span></li>
<li><code>></code> <span>Greater than operator.</span></li>
<li><code><</code> <span>Less than operator.</span></li>
<li><code>>=</code> <span>Greater than or equal to operator.</span></li>
<li><code><=</code> <span>Less than or equal to operator.</span></li>
<li><code>&&</code> <span>Logical AND operator.</span></li>
<li><code>||</code> <span>Logical OR operator.</span></li>
<li><code>!</code> <span>Logical NOT operator.</span></li>
<li class="new"><code>!</code> <span>factorial operator if you use it after a number or a special
variable.</span></li>
<li class="new"><code>||</code> <span>absloute operator if you put a number or a special variable between
it.</span></li>
<li class="new"><code>^</code> <span>XOR operator.</span></li>
<li class="new"><code>!^</code> <span>XNOR operator.</span></li>
<li class="new"><code>!&</code> <span>NAND operator.</span></li>
<li class="new"><code>!|</code> <span>NOR operator.</span></li>
<li>
<code><<</code> <span>Left shift assignment operator.
</span>
</li>
<li>
<code>>></code> <span>Right shift assignment operator.
</span>
</li>
<li>
<code>&</code> <span>Bitwise AND operator.
</span>
</li>
<li>
<code>|</code> <span>Bitwise OR operator.
</span>
</li>
<li>
<code>~</code> <span>Bitwise NOT operator.
</span>
</li>
<li>
<code>^</code> <span>Bitwise XOR operator.
</span>
</li>
<li>
<code>&=</code> <span>Bitwise AND assignment operator.
</span>
</li>
<li>
<code>|=</code> <span>Bitwise OR assignment operator.
</span>
</li>
<li>
<code>^=</code> <span>Bitwise XOR assignment operator.
</span>
</li>
<li>
<code>~</code> <span>Bitwise NOT operator.
</span>
</li>
<li>
<code><<=</code> <span>Left shift assignment operator.
</span>
</li>
<li>
<code>>>=</code> <span>Right shift assignment operator.
</span>
</li>
<li>
<code>&&=</code> <span>Logical AND assignment operator.
</span>
</li>
<li>
<code>||=</code> <span>Logical OR assignment operator.
</span>
</li>
<li>
<code>??</code> <span>Nullish coalescing operator.
</span>
</li>
<li>
<code>??=</code> <span>Nullish coalescing assignment operator.
</span>
</li>
<li>
<code>?.</code> <span>Optional chaining operator.
</span>
</li>
<li>
<code>?:</code> <span>Ternary operator.
</span>
</li>
</ol>
</p>
<h2>Basic keywords</h2>
<table>
<thead>
<tr>
<th>Keyword</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>velt</td>
<td>Declares a block-scoped variable.</td>
</tr>
<tr>
<td>if</td>
<td>Used to specify a block of code to be executed if a condition is true.</td>
</tr>
<tr>
<td>else</td>
<td>Used to specify a block of code to be executed if the same condition is false.</td>
</tr>
</tr>
<tr>
<td>while</td>
<td>Creates a loop that executes a block of code as long as the condition is
</td>
</tr>
<tr>
<td>break</td>
<td>Terminates the current loop or switch statement.</td>
</tr>
<tr>
<td>case</td>
<td>Specifies a block of code to be executed in a switch statement.</td>
</tr>
<tr>
<td>catch</td>
<td>Specifies a block of code to be executed when an error occurs in a try block.</td>
</tr>
<tr>
<td>class</td>
<td>Declares a class.</td>
</tr>
<tr>
<td>velc</td>
<td>Declares a block-scoped constant (read-only) variable.</td>
</tr>
<tr>
<td>continue</td>
<td>Skips the current iteration of a loop and continues with the next iteration.</td>
</tr>
<tr>
<td>debugger</td>
<td>Stops the execution of JavaScript and calls the debugging function.</td>
</tr>
<tr>
<td>default</td>
<td>Specifies a default case in a switch statement.</td>
</tr>
<tr>
<td>delete</td>
<td>Deletes an object's property.</td>
</tr>
<tr>
<td>do</td>
<td>Creates a loop that executes a block of code as long as the condition is true.</td>
</tr>
<tr>
<td>else</td>
<td>Specifies a block of code to be executed if the condition in an if statement is false.</td>
</tr>
<tr>
<td>extends</td>
<td>Specifies the class to be inherited from in a class definition.</td>
</tr>
<tr>
<td>finally</td>
<td>Specifies a block of code to be executed after a try/catch block.</td>
</tr>
<tr>
<td>for</td>
<td>Creates a loop that consists of three optional expressions: initialization, condition, and final
expression. Separate expressions with a coma(,).
</td>
</tr>
<tr>
<td>function</td>
<td>Declares a function.</td>
</tr>
<tr>
<td>if</td>
<td>Specifies a block of code to be executed if a condition is true.</td>
</tr>
<tr>
<td>#include</td>
<td>Used to import functions, objects, or values from a module.</td>
</tr>
<tr>
<td>in</td>
<td>Checks if a specified property is in a specified object.</td>
</tr>
<tr>
<td>instanceof</td>
<td>Checks if an object is an instance of a specified object type.</td>
</tr>
<tr>
<td>let</td>
<td>Declares a block-scoped variable.</td>
</tr>
<tr>
<tdd>
<td>Creates an instance of an object or a user-defined type.</td>
</tr>
<tr>
<td>return</td>
<td>Specifies the value to be returned by a function.</td>
</tr>
<tr>
<td>super</td>
<td>Refers to the superclass in a class definition.</td>
</tr>
<tr>
<td>switch</td>
<td>Evaluates an expression and executes a block of code based on a matching case.</td>
</tr>
<tr>
<td>this</td>
<td>Refers to the current object.</td>
</tr>
<tr>
<td>throw</td>
<td>Throws an exception (user-defined or built-in).</td>
</tr>
<tr>
<td>try</td>
<td>Specifies a block of code to be tested for errors.</td>
</tr>
<tr>
<td>typeof</td>
<td>Returns a string indicating the type of a variable or expression.</td>
</tr>
<tr>
<td>var</td>
<td>Declares a variable.</td>
</tr>
<tr>
<td>void</td>
<td>Specifies that an expression should be evaluated without returning a value.</td>
</tr>
<tr>
<td>while</td>
<td>Creates a loop that executes a block of code as long as the condition is true.</td>
</tr>
<tr>
<td>with</td>
<td>Adds a block of code with a specified object as the scope.</td>
</tr>
<tr>
<td>yield</td>
<td>Pauses and resumes a generator function.</td>
</tr>
</tbody>
</table>
<p class="license" xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a
property="dct:title" rel="cc:attributionURL"
href="https://github.com/MarufHasan24/jsr/blob/main/compiler.html">javascript reverse
</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName"
href="https://github.com/MarufHasan24">Md. maruf hasan</a> is licensed under <a
href="http://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1" target="_blank"
rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC 4.0<img
style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img
style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img
style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1">
</a>
</p>
</body>
</html>