-
Notifications
You must be signed in to change notification settings - Fork 0
/
exa_grammar.ohm
112 lines (92 loc) · 3.2 KB
/
exa_grammar.ohm
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
EXAScript {
Program = Instruction*
Instruction = CopyInstr
| AddInstr
| SwizInstr
| MarkInstr
| JumpInstr
| TJumpInstr
| FJumpInstr
| TestInstr
| ReplInstr
| HaltInstr
| KillInstr
| LinkInstr
| HostInstr
| ModeInstr
| VoidInstr
| MakeInstr
| GrabInstr
| FileInstr
| SeekInstr
| DropInstr
| WipeInstr
| NoopInstr
| noteInstr
| RandInstr
| AddInstruction
| SubtractInstruction
| MultiplyInstruction
| DivideInstruction
| LoopMacro
Register = GeneralRegister
| TestRegister
| FileRegister
| MessageRegister
| HardwareRegister
EXANumber = "-" digit4 -- negative
| digit4 -- positive
// there must be a better way to do this
digit4 = digit digit? digit? digit? space?
GeneralRegister = "X"
TestRegister = "T"
FileRegister = "F"
MessageRegister = "M"
HardwareRegister = "#" validString
Parameter = Register | EXANumber
label = validString //alnum+ newline
newline = "\n"
TestSubChars = "<" | "=" | ">"
onlySpace = " " // todo make a more elegant solution to this
validString = onlySpace? (alnum | "_")* newline?
// apparently in ohm space is any whitespace not " " so i got messed up real bad
validNoteString = onlySpace? (alnum | "_" | onlySpace)*
CopyInstr = "COPY" Parameter Register // works
AddInstr = "ADDI" Parameter Parameter Parameter
SwizInstr = "SWIZ" Parameter Parameter Register
MarkInstr = "MARK" label
JumpInstr = "JUMP" label
TJumpInstr = "TJMP" label
FJumpInstr = "FJMP" label
TestInstr = "TEST" Parameter TestSubChars Parameter -- value
| "TEST" "MRD" -- comm
| "TEST" "EOF" -- file
// Interaction with other EXAs
ReplInstr = "REPL" label
HaltInstr = "HALT"
KillInstr = "KILL"
// Exa Movement and Host Inters
LinkInstr = "LINK" Parameter
HostInstr = "HOST" Register
// EXA State Instructions
ModeInstr = "MODE"
VoidInstr = "VOID" MessageRegister
| "VOID" FileRegister
// File Instructions
MakeInstr = "MAKE"
GrabInstr = "GRAB" Parameter
FileInstr = "FILE" Register
SeekInstr = "SEEK" Parameter
DropInstr = "DROP"
WipeInstr = "WIPE"
// Auxilary Instructions
NoopInstr = "NOOP"
noteInstr = "NOTE" validNoteString
RandInstr = "RAND" Parameter Parameter Register
// Arithmetic
AddInstruction = "ADDI" Parameter Parameter Register
SubtractInstruction = "SUBI" Parameter Parameter Register
MultiplyInstruction = "MULI" Parameter Parameter Register
DivideInstruction = "DIVI" Parameter Parameter Register
LoopMacro = "@REP" digit Instruction* "@END"
}