This repository has been archived by the owner on Mar 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
um.js
79 lines (63 loc) Β· 2.18 KB
/
um.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
'use strict';
class Um {
constructor(code) {
this.tokens = [];
this.code = code;
this.lexer();
}
lexer() {
let pointer = 0;
let ch = '';
let token = '';
while(pointer < this.code.length) {
ch = this.code[pointer];
token += ch;
if (ch == 'μ€') {
pointer++;
while (pointer < this.code.length) {
ch = this.code[pointer];
if (ch == '.') {
token += ch;
pointer++;
}else {
break;
}
}
this.tokens.push(['STACK_OUTPUT' ,token]);
token = '';
continue;
} else if (ch == 'μΌ' || ch == 'μ' || ch == '.') {
// μ΄μ§μ 체ν¬
// token = '';
pointer++;
while (pointer < this.code.length) {
ch = this.code[pointer];
if (ch == 'μΌ' || ch == 'μ' || ch == '.') {
token += ch;
pointer++;
}else {
break;
}
}
this.tokens.push(['NUMBER' ,token]);
token = '';
continue;
} else if (token == '?' || token =='!' || token == '??' || token == '!!' || token == '?!') {
if(!(pointer + 1 <= this.code.length && (this.code[pointer + 1] == '?' || this.code[pointer + 1] == '!'))) {
this.tokens.push(['OPERATOR', token]);
token = '';
}
} else if (ch == ';') {
if(!(pointer + 1 <= this.code.length && this.code[pointer + 1] == ';')) {
this.tokens.push(['STACK_INPUT', token]);
token = '';
}
}
pointer++;
}
console.log(this.tokens);
}
parser() {
}
}
module.exports = Um;