-
Notifications
You must be signed in to change notification settings - Fork 0
/
FunctionEvaluatorState.cs
82 lines (72 loc) · 2.3 KB
/
FunctionEvaluatorState.cs
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
namespace Muftec.Lib.CompilerStates
{
class FunctionEvaluatorState : EvaluatorState
{
public FunctionEvaluatorState(ApplicationCore core) : base(core)
{
IsFunction = true;
}
public new bool EvaluateToken(string token)
{
if (EvaluateAllToken(token))
return true;
// Strings
if (token.StartsWith("\""))
{
CurrentMachine = new StringState("\"");
if (!CurrentMachine.EvaluateToken(token))
{
var ss = CurrentMachine as StringState;
Core.Queue.Enqueue(ss.ResultString);
CurrentMachine = null;
}
return true;
}
// Conditionals
if (token.ToLower() == "if")
{
CurrentMachine = new ConditionalState(Core);
return true;
}
if (EvaluateSuperToken(token))
{
return true;
}
// Floats
double floatVal;
if (double.TryParse(token, out floatVal))
{
if (token.Contains("."))
{
Core.Queue.Enqueue(floatVal);
return true;
}
}
// Integers
int intVal;
if (int.TryParse(token, out intVal))
{
Core.Queue.Enqueue(intVal);
return true;
}
// Symbols
if (Core.Variables.Contains(token))
{
Core.Queue.Enqueue(new MuftecStackItem(token, MuftecAdvType.Variable, Core.LineNumber));
return true;
}
if (Core.Functions.ContainsKey(token))
{
Core.Queue.Enqueue(new MuftecStackItem(token, MuftecAdvType.Function, Core.LineNumber));
return true;
}
// OpCodes - assume any remaining value is an opcode, don't need to check
Core.Queue.Enqueue(new MuftecStackItem(token, MuftecAdvType.OpCode, Core.LineNumber));
return true;
}
protected virtual bool EvaluateSuperToken(string token)
{
return false;
}
}
}