-
Notifications
You must be signed in to change notification settings - Fork 0
/
LR1Action.cs
37 lines (28 loc) · 1.09 KB
/
LR1Action.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
namespace ParserGen;
internal class LR1Action : IAction {
internal ActionType Action { get; set; }
internal int ActionArgument { get; set; }
internal LR1Action(ActionType action) {
this.Action = action;
this.ActionArgument = 0;
}
internal LR1Action(ActionType action, int index) {
this.Action = action;
this.ActionArgument = index;
}
public override string ToString() => this.Action switch {
ActionType.Goto => $"-> {this.ActionArgument}",
ActionType.Shift => $"S({this.ActionArgument})",
ActionType.Reduce => $"R({this.ActionArgument})",
ActionType.Accept => "Accept",
_ => string.Empty
};
public uint Encode() => this.Action switch {
ActionType.Accept => 0x1u,
ActionType.Shift => (uint)(0x10000000u | (this.ActionArgument)),
ActionType.Reduce => (uint)(0x20000000u | (this.ActionArgument)),
ActionType.Goto => (uint)(0x30000000u | (this.ActionArgument)),
_ => 0x0u
};
public string EncodedString() => "0x" + this.Encode().ToString("X") + "u";
}