Initial commit

This commit is contained in:
Paul Mathieu
2021-02-17 13:20:30 -08:00
commit 363944d417
35 changed files with 3318 additions and 0 deletions

45
tools/as.ebnf Normal file
View File

@@ -0,0 +1,45 @@
COMMENT: /\/\/[^\n]*/
!opcode: "nop"i
| "load"i
| "store"i
| "add"i
| "sub"i
| "and"i
| "or"i
| "not"i
| "xor"i
| "seth"i
| "shr"i
| "cmp"i
| "mul"i
| "beq"i
| "set"i
| "bneq"i
!register: REGISTER
| "sp"i
| "lr"i
| "pc"i
LABEL: /[a-z_]\w*/i
REGISTER: /[Rr]\d+/
start: line*
?line: label | statement | raw_word | symbol_def
label: LABEL ":"
statement: opcode [param ("," param)*]
!label_ref: LABEL
!immediate: SIGNED_NUMBER | HEX_LITTERAL
?param: register | label_ref | reg_offset | immediate
reg_offset: "[" register ("," immediate)? "]"
raw_word: ".word" immediate
symbol_def: ".global" label_ref
HEX_LITTERAL: /0x[a-fA-F0-9]+/
%import common.WS
%import common.SIGNED_NUMBER
%ignore COMMENT
%ignore WS