-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandBuilder.cs
More file actions
70 lines (58 loc) · 1.99 KB
/
CommandBuilder.cs
File metadata and controls
70 lines (58 loc) · 1.99 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
//Currently, the entire implementation of Commands/CommandBuilder.cs SUCKS MAJORLY!
//Basically, I assume that there are two commands: :l "path", and :s "path" (loadvars and savevars)
//In this case, a field is either 'l' or 's' and is in the beggining, and string comes directly afterwards.
//Yes, this sucks. Maybe I'll fix it if I ever feel like expanding commans.
using System;
using System.Text;
using System.Collections.Generic;
class CommandBuilder : IBuilder<string> {
private char command;
private List<double> args;
public CommandBuilder() {
args = new List<double>();
}
public string Number(string number) {
return number;
}
public string Variable(string name) {
return '$' + name;
}
public string Field(string name) {
return name;
}
public string Assignment(LexType op, string name, string value) {
return Scanner.OpNames[(int)op] + ' ' + name + ' ' + value;
}
public string String(string str) {
return str;
//throw new Exception("Strings are not (yet) allowed in command");
}
public string Function(string name, List<string> args) {
int limit = 0;
StringBuilder sb = new StringBuilder();
sb.Append(name);
while (limit < args.Count) {
sb.Append(args[limit]);
sb.Append(' ');
limit++;
}
return sb.ToString();
}
public string Binary(LexType op, string left, string right) {
return Scanner.OpNames[(int)op] + ' ' + left + ' ' + right;
}
public string Unary(LexType op, string expr) {
switch (op) {
case LexType.Minus:
case LexType.Plus:
return Scanner.OpNames[(int)op] + ' ' + expr;
case LexType.Exclamation:
return expr + '!';
default:
throw new Exception("Internal Error. Invalid unary operator.");
}
}
public string End(string expr) {
return expr;
}
}