-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.js
804 lines (694 loc) · 20.9 KB
/
interpreter.js
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
// MEMORY SET-UP WITH SOME NATIVE FUNCTIONS
let memory = {
print: {
isNative: true,
type: 'fn',
name:'print',
params: [],
body: (params) => {
let arrToPrint = [];
for (var i in params) {
if(i === '0') continue;
if (params[i].body) {
arrToPrint.push(params[i].body);
} else if (typeof params[i] === 'number') {
arrToPrint.push(params[i]);
} else {
arrToPrint.push(params[i].split('').filter(e => {
if (e === '"') return false;
return true;
}).join(''));
}
}
arrToPrint.length === 1 ? console.log(arrToPrint[0]) : console.log(arrToPrint.join(' '));
}
},
push:{
isNative: true,
type: 'fn',
name:'push',
params: [],
body: (params) => {
let thiss = params[0];
let arrVariable = params[1];
let thingToPush = params[2];
if (parseInt(thingToPush)) thingToPush = parseInt(thingToPush);
if (typeof thingToPush === 'object') thingToPush = thingToPush.body;
let arrToPushTo = thiss.getVariable(arrVariable.name).body;
arrToPushTo.push(thingToPush);
thiss.memory[arrVariable.name].body = arrToPushTo;
return;
}
},
index:{
isNative: true,
type: 'fn',
name:'index',
params: [],
body: (params) => {
let thiss = params[0];
let arrVariable = params[1];
let indexToGet = params[2];
let returnVal = thiss.getVariable(arrVariable.name).body[indexToGet];
return returnVal;
}
},
};
function Interpreter(memory) {
this.memory = memory;
this.stack = [];
this.queue = [];
}
/* TOKENIZATION & INPUT METHODS */
Interpreter.prototype.tokenize = function(text) {
var regex = /\s*(=>|["-+*\][\/\%:\(\)]|[A-Za-z_][A-Za-z0-9_]*|[0-9]*\.?[0-9]+)\s*/g;
return text.split(regex).filter(function (s) { return !s.match(/^\s*$/); });
};
Interpreter.prototype.input = function(text) {
this.tokens = this.tokenize(text);
if (!this.tokens.length) {
return "";
}
return this.program();
};
/* MEMORY METHODS */
Interpreter.prototype.getVariable = function(name) {
return this.memory[name];
};
Interpreter.prototype.addVariable = function(type, name, params, body) {
this.memory[name] = {
isNative: false,
name: name,
type: type,
params: params,
body: body
};
};
Interpreter.prototype.resetParams = function(name) {
let func = this.getVariable(name);
func.params = [];
};
/* CORE METHODS */
Interpreter.prototype.peek = function() {
return this.tokens[0] || null;
};
Interpreter.prototype.get = function() {
return this.tokens.shift();
};
Interpreter.prototype.consumeAndRunUntilBreak = function() {
this.get();
let returnValue = [];
while (!this.isWrapper() && this.tokens.length) returnValue.push(this.get());
let newInterpreter = new Interpreter(this.memory);
return newInterpreter.input(returnValue.join(" "));
};
Interpreter.prototype.consumeUntilFunctionWrapper = function(char, returnType) {
let returnValue;
switch(returnType) {
case "string":
returnValue = "";
while (this.peek() !== char) returnValue += this.get();
break;
case "array":
returnValue = [];
let conditionalKeywords = ["if", "elsif", "else"],
isLoopKeywords = ["from"],
wrapperCounter = 0,
conditionalKeywordCounter = 0,
testCounter = 0;
if (char === ":") {
while (this.peek() !== char || wrapperCounter !== conditionalKeywordCounter * 2 || this.isConditionalKeyword()) {
if (this.isWrapper()) wrapperCounter++;
if (this.isConditionalKeyword() || this.isLoopKeyword()) conditionalKeywordCounter++;
returnValue.push(this.get());
testCounter++;
}
} else {
while (this.peek() !== char) {
returnValue.push(this.get());
}
}
break;
default:
break;
}
return returnValue;
};
Interpreter.prototype.consumeUntil = function(char, returnType) {
let returnValue;
switch(returnType) {
case "string":
returnValue = "";
while (this.peek() !== char) returnValue += this.get();
break;
case "array":
returnValue = [];
let conditionalKeywords = ["if", "elsif", "else"],
isLoopKeywords = ["from"],
wrapperCounter = 0,
conditionalKeywordCounter = 0,
testCounter = 0;
if (char === ":") {
while (this.peek() !== char || wrapperCounter !== conditionalKeywordCounter * 2) {
if (this.isWrapper()) wrapperCounter++;
if (this.isConditionalKeyword() || this.isLoopKeyword()) conditionalKeywordCounter++;
returnValue.push(this.get());
testCounter++;
if (testCounter > 100) break;
}
} else if (char === ")") {
let openingParenCounter = 0,
closingParenCounter = 0;
while (this.peek() !== char || openingParenCounter !== closingParenCounter) {
if (this.isOpeningParen()) openingParenCounter++;
if (this.isClosingParen()) closingParenCounter++;
returnValue.push(this.get());
testCounter++;
if (testCounter > 100) break;
}
} else {
while (this.peek() !== char) {
returnValue.push(this.get());
}
}
break;
default:
break;
}
return returnValue;
};
Interpreter.prototype.replace = function(thingToReplace, thingToReplaceWith, arr) {
return arr.map(e => {
if (e === thingToReplace) return thingToReplaceWith;
return e;
});
};
Interpreter.prototype.convertArr = function(testArr) {
let arrToReturn = testArr;
let openingIndex = testArr.indexOf('[');
let closingIndex = testArr.lastIndexOf(']');
if (openingIndex !== -1) {
let substr = testArr.substring(openingIndex+1,closingIndex);
arrToReturn = Array.from(substr).filter(e => {
if (e === ',' ) return false;
return true;
});
}
for (var i in arrToReturn) {
if (parseInt(arrToReturn[i])) arrToReturn[i] = parseInt(arrToReturn[i]);
}
return arrToReturn;
}
/* KEYWORD METHODS */
Interpreter.prototype.isFunctionKeyword = function() {
return this.peek() === "fn";
};
Interpreter.prototype.isVariableKeyword = function() {
return ["fn", "num", "str", "arr", "bool"].includes(this.peek());
};
Interpreter.prototype.isConditionalKeyword = function() {
return ["if", "elsif", "else"].includes(this.peek());
};
Interpreter.prototype.isLoopKeyword = function() {
return ["from"].includes(this.peek());
};
Interpreter.prototype.getConditionalKeyword = function() {
return this.peek();
};
Interpreter.prototype.getLoopKeyword = function() {
return this.peek();
};
/* OPERATOR METHODS */
Interpreter.prototype.isWrapper = function() {
return this.peek() === ":";
};
Interpreter.prototype.isOpeningArr = function() {
return this.peek() === "[";
};
Interpreter.prototype.isClosingArr = function() {
return this.peek() === "]";
};
Interpreter.prototype.isStringWrapper = function() {
return this.peek() === "\"";
};
Interpreter.prototype.isAssignmentOperator = function() {
return this.peek() === "=";
};
Interpreter.prototype.isComparisonOperator = function() {
return this.peek() === "==";
};
Interpreter.prototype.isTermOperator = function() {
return "+-".includes(this.peek());
};
Interpreter.prototype.isFactorOperator = function() {
return "*/%".includes(this.peek());
};
Interpreter.prototype.isAdditiveInverseOperator = function() {
return this.peek() === "-";
};
Interpreter.prototype.isOpeningParen = function() {
return this.peek() === "(";
};
Interpreter.prototype.isClosingParen = function() {
return this.peek() === ")";
};
Interpreter.prototype.isReturnOperator = function() {
return this.peek() === "=>";
};
/* PRIMITIVE TYPE METHODS */
Interpreter.prototype.isLetter = function() {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
return letters.includes(this.peek()[0]);
};
Interpreter.prototype.isDigit = function() {
return "0123456789".includes(this.peek()[0]);
};
Interpreter.prototype.isBoolean = function() {
return ["true", "false"].includes(this.peek());
};
Interpreter.prototype.getNumber = function() {
if (!this.isDigit()) {
return null;
} else {
return parseFloat(this.get());
}
};
Interpreter.prototype.getIdentifier = function() {
if (!this.isLetter()) {
return null;
} else {
return this.get();
}
};
/* MAJOR OPERATION METHODS */
Interpreter.prototype.functionCall = function(currentFunction) {
if (!this.isOpeningParen()) throw new Error("A function call must have arguments wrapped in parentheses!");
this.get();
let currentArguments = this.consumeUntil(")", "array");
if (currentArguments.length) currentArguments = currentArguments.join("").split(",");
if (!this.isClosingParen()) throw new Error("A function call must have arguments wrapped in parentheses!");
this.get();
if (currentFunction.isNative) {
currentFunction.params.push(this)
for (let i in currentArguments) {
let funcName = currentArguments[i].substring(0,currentArguments[i].indexOf('('));
if (this.getVariable(currentArguments[i])) {
currentFunction.params.push(this.getVariable(currentArguments[i]));
}
else if (this.getVariable(funcName)) {
let newInterpreter = new Interpreter(this.memory);
currentFunction.params.push(newInterpreter.input(currentArguments[i]));
}
else {
currentFunction.params.push(currentArguments[i]);
}
}
let returnVal = currentFunction.body(currentFunction.params);
this.resetParams(currentFunction.name);
return returnVal;
}
let otherInterpreter = new Interpreter(this.memory);
let bodyToParse = currentFunction.body.slice(0);
for (let j = 0; j < currentArguments.length; j++) {
let currentArgument;
if (this.getVariable(currentArguments[j]) && this.getVariable(currentArguments[j]).type === "fn") {
currentArgument = currentArguments[j];
} else {
currentArgument = otherInterpreter.input(currentArguments[j]) || currentArguments[j];
}
let parameterToReplace = currentFunction.params[j].name;
switch(currentFunction.params[j].type) {
case "num":
if (typeof parseFloat(currentArgument) !== "number" || isNaN(parseFloat(currentArgument))) throw new Error("Functions should only be called with parameters of the correct type!");
break;
case "str":
if (currentArgument[0] !== '"') throw new Error("Functions should only be called with parameters of the correct type!");
break;
case "bool":
if (currentArgument !== "true" && currentArgument !== "false") throw new Error("Functions should only be called with parameters of the correct type!");
break;
case "fn":
if (!this.getVariable(currentArgument) || this.getVariable(currentArgument).type !== "fn") throw new Error("Functions should only be called with parameters of the correct type!");
break;
case "arr":
break;
default:
throw new Error("Functions should only be called with parameters of the correct type!");
break;
}
bodyToParse = bodyToParse.map(element => {
if (element === parameterToReplace) {
return currentArgument;
} else {
return element;
}
});
}
return otherInterpreter.input(bodyToParse.join(" "));
};
Interpreter.prototype.factor = function() {
let factorResult = this.getNumber();
if (factorResult !== null) {
return factorResult;
} else if (this.isStringWrapper()) {
this.get();
factorResult = this.consumeUntil('"', "string");
this.get();
return factorResult;
}
else if (this.isAdditiveInverseOperator()) {
this.get();
factorResult = this.factor();
return -factorResult;
} else if (this.isOpeningParen()) {
this.get();
factorResult = this.expression();
if (!this.isClosingParen()) throw new Error("Parentheses should always be properly closed!");
this.get();
return factorResult;
} else if (this.isBoolean()) {
factorResult = this.get();
return factorResult;
} else if (this.isOpeningArr()) {
factorResult = this.peek();
factorResult = this.consumeUntil(']', "string");
factorResult += this.peek();
this.get();
return factorResult;
}
factorResult = this.getIdentifier();
if (factorResult) {
let variable = this.getVariable(factorResult);
if (variable) {
switch(variable.type) {
case "fn":
return this.functionCall(variable);
break;
default:
return variable.body;
break;
}
} else {
throw new Error(`The identifier ${factorResult} was never declared as a variable!`);
}
}
};
Interpreter.prototype.term = function() {
var termResult = this.factor();
while (this.isFactorOperator()) {
if (this.peek() === "*") {
this.get();
termResult *= this.factor();
} else if (this.get() === "/") {
termResult /= this.factor();
} else {
termResult %= this.factor();
}
}
return termResult;
};
Interpreter.prototype.expression = function() {
let expressionResult = this.term();
while (this.isTermOperator()) {
if (this.get() === "+") {
expressionResult += this.term();
} else {
expressionResult -= this.term();
}
}
return expressionResult;
};
Interpreter.prototype.comparison = function() {
let firstExpression = this.expression();
if (this.isComparisonOperator()) {
this.get();
return firstExpression === this.expression();
}
if (typeof firstExpression !== "boolean") throw new Error("A condition must be a boolean!");
return firstExpression;
};
/* DECLARATIONS, LOOPS, & CONDITIONALS METHODS */
Interpreter.prototype.functionDeclaration = function() {
if (!this.isOpeningParen()) throw new Error("A function's parameters should always be wrapped in parentheses!");
this.get();
let functionParameters = this.consumeUntil(")", "array");
let validParameterTypes = ["fn", "num", "str", "arr", "bool"];
for (let i = 0; i < functionParameters.length; i++) {
let currentElement = functionParameters[i];
if (i % 3 === 0 && !["fn", "num", "str", "arr", "bool"].includes(currentElement)) {
throw new Error("All function parameters must have valid types!");
} else if (i % 3 === 1) {
//
} else if (i % 3 === 2 && currentElement !== ",") {
throw new Error("All function parameters must be separated by commas!");
}
}
functionParameters = functionParameters.filter(element => element !== ",");
let actualFunctionParameters = [];
for (let j = 1; j < functionParameters.length; j += 2) {
actualFunctionParameters.push({
type: functionParameters[j - 1],
name: functionParameters[j]
})
}
if (!this.isClosingParen()) throw new Error("A function's parameters should always be wrapped in parentheses!");
this.get();
if (!this.isWrapper()) throw new Error("A function declaration requires an opening wrapper!");
this.get();
let functionBody = this.consumeUntilFunctionWrapper(":", "array");
if (!this.isWrapper()) throw new Error("A function declaration requires a closing wrapper!");
this.get();
return [actualFunctionParameters, functionBody];
};
Interpreter.prototype.variableDeclaration = function() {
let variableType = this.get(),
variableName = this.getIdentifier(),
variableParams = null,
variableBody;
if (!this.isAssignmentOperator()) throw new Error("A variable declaration requires a valid assignment operator!");
this.get();
switch (variableType) {
case "fn":
let functionInformation = this.functionDeclaration();
variableParams = functionInformation[0];
variableBody = functionInformation[1];
break;
case "num":
variableBody = this.expression();
if (typeof variableBody !== "number") throw new Error("The 'num' type requires a valid number!");
break;
case "str":
variableBody = this.expression();
if (typeof variableBody !== "string") throw new Error("The 'str' type requires a valid string!");
break;
case "arr":
variableBody = this.expression();
variableBody = this.convertArr(variableBody)
if (!Array.isArray(variableBody)) throw new Error("The 'arr' type requires a valid array!");
break;
case "bool":
variableBody = this.expression();
if (typeof variableBody !== "boolean") throw new Error("The 'bool type requires a valid boolean!");
break;
default:
throw new Error("Variable assignment requires a valid variable type!");
}
this.addVariable(variableType, variableName, variableParams, variableBody);
};
Interpreter.prototype.conditional = function() {
if (this.getConditionalKeyword() !== "if") {
this.consumeUntil(":", "array");
} else {
this.get();
let condition = this.comparison();
while (!condition) {
if (!this.isWrapper()) throw new Error("A conditional statement requires an opening wrapper!");
this.get();
this.consumeUntil(":", "array");
if (!this.isWrapper()) throw new Error("A conditional statement requires a closing wrapper!");
this.get();
if (this.isConditionalKeyword()) {
if (this.getConditionalKeyword() === "else") {
this.get();
if (!this.isWrapper()) throw new Error("A conditional statement requires an opening wrapper!");
this.get();
if (this.isReturnOperator()) {
return this.program();
} else {
this.program();
}
if (!this.isWrapper()) throw new Error("A conditional statement requires a closing wrapper!");
this.get();
break;
} else if (this.getConditionalKeyword() === "elsif") {
this.get();
condition = this.comparison();
} else {
break;
}
} else {
break;
}
}
if (condition) {
if (!this.isWrapper()) throw new Error("A conditional statement requires an opening wrapper!");
this.get();
if (this.isReturnOperator()) {
return this.program();
} else {
this.program();
}
if (!this.isWrapper()) throw new Error("A conditional statement requires a closing wrapper!");
this.get();
}
}
};
Interpreter.prototype.loop = function() {
let firstIndex, finalIndex, variableName, loopBody;
if (this.peek() === 'from') {
this.get();
if (isNaN(this.peek())) throw new Error('A from loop should be followed by a number!');
firstIndex = this.get();
if (this.peek() !== 'to') throw new Error('A from loop should always include the "to" keyword!');
this.get();
if (isNaN(parseInt(this.peek()))) throw new Error('The "to" keyword should always be followed by a number!');
finalIndex = this.get();
if (this.peek() !== 'with') throw new Error('A from loop should always include the "with" keyword!');
this.get();
if (!this.isLetter()) throw new Error('The "with" keyword should always be followed by a proper identifier!');
variableName = this.get();
if (!this.isWrapper()) throw new Error('A from loop should always have a proper wrapper!');
this.get();
loopBody = this.consumeUntil(':', 'array');
let children = [];
firstIndex = parseInt(firstIndex);
finalIndex = parseInt(finalIndex);
if (firstIndex <= finalIndex) {
for (var i = firstIndex; i <= finalIndex; i++) {
children.push(this.replace(variableName, i, loopBody));
}
} else if (firstIndex > finalIndex) {
for (var i = firstIndex; i >= finalIndex; i--) {
children.push(this.replace(variableName, i, loopBody));
}
}
children.forEach(e => {
let otherInterpreter = new Interpreter(this.memory);
otherInterpreter.input(e.join(" "));
});
} else if (this.peek() === 'while') {
} else {
throw new Error('Invalid loop type m8!');
}
};
Interpreter.prototype.program = function() {
while (this.tokens.length) {
if (this.isVariableKeyword()) {
this.variableDeclaration();
} else if (this.isConditionalKeyword()) {
let possibleReturnValue = this.conditional();
if (possibleReturnValue !== undefined) return possibleReturnValue;
} else if (this.isLoopKeyword()) {
this.loop();
} else if (this.isReturnOperator()) {
return this.consumeAndRunUntilBreak();
} else {
let result = this.expression();
return result;
}
}
};
// INTERPRETER INSTANTIATION
let Oak = new Interpreter(memory)
// BASIC VARIABLE DECLARATION
// Running "Oak.memory" will show that the newly-declared
// variables are stored in memory.
Oak.input(`
num one = 1
num three = 3
str hello = "hello"
arr array = [1, 2, 3, 4, 5, 6, 7]
fn add = (num a, num b) :
=> a + b
:
fn echo = (num a) :
=> a
:
`)
// Oak.memory
// BASIC FUNCTION CALLING
// Oak.input(`
// add(one, three) + add(echo(one), three)
// `)
// BASIC IF / ELSE STATEMENTS
// Oak.input(`
// if 3 == 3 :
// print("First!")
// : elsif echo(one) == 1 :
// print("Second!")
// : else :
// print("Third!")
// :
// `)
// BASIC FROM TO LOOPS
// Oak.input(`
// from 0 to 6 with i :
// num currentIndexValue = index(array, i)
// print(currentIndexValue)
// :
// `)
// NESTED FROM TO LOOPS
// Oak.input(`
// from 1 to 3 with i :
// from 1 to 3 with j :
// from 1 to 3 with k :
// print(i, j, k)
// :
// :
// :
// `)
// FIZZBUZZ
// Oak.input(`
// fn fizzBuzz = (num n) :
// from 1 to n with i :
// if i % 15 == 0 :
// print("FizzBuzz")
// : elsif i % 5 == 0 :
// print("Buzz")
// : elsif i % 3 == 0 :
// print("Fizz")
// : else :
// print(i)
// :
// :
// :
// `)
// Oak.input(`
// fizzBuzz(35)
// `)
// RECURSION & FIBONACCI
// Oak.input(`
// fn fib = (num n) :
// if n == 1 :
// => 0
// : elsif n == 2 :
// => 1
// : else :
// => fib(n - 1) + fib(n - 2)
// :
// :
// `)
// Oak.input(`
// from 1 to 15 with i :
// print(i, fib(i))
// :
// `)
// ORDER OF OPERATIONS
// Oak.input(`
// fn alwaysTwo = (num n) :
// => ((((n + 47 % (19 * add(-3, 5))) * echo(three - one) - 4) / fib(4) - n + fib(echo(10)) - 29) * 3 - 9) / 3 - (((n + 109 % 10) * 2 - 4) / 2 - n)
// :
// `)
// Oak.input(`
// alwaysTwo(4751)
// `)