-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloo.dart
56 lines (48 loc) · 1.15 KB
/
loo.dart
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
import 'dart:io';
class LooInterpreter {
int position = 0;
int ascii = 0;
late String data;
LooInterpreter(String data) {
this.data = data;
}
void execute() {
String character = this.currentCharacter();
while(character != ";"){
if(character == "+"){
this.ascii += 1;
} else if(character == "-"){
this.ascii -= 1;
} else if(character == "#") {
stdout.write(String.fromCharCode(this.ascii));
}
this.position += 1;
character = this.currentCharacter();
}
}
String currentCharacter() {
if(this.data.length == this.position) {
return ";";
} else {
return this.data[this.position];
}
}
}
String createSource(List<String> arguments){
if(arguments.length == 0){
return "";
}
String filename = arguments[0];
return filename;
}
void main(List<String> arguments) {
String filename = createSource(arguments);
if(filename.length == 0){
print("No filename specified");
} else {
File(filename).readAsString().then((String content) {
LooInterpreter interpreter = new LooInterpreter(content);
interpreter.execute();
});
}
}