46 lines
		
	
	
		
			842 B
		
	
	
	
		
			EBNF
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			842 B
		
	
	
	
		
			EBNF
		
	
	
	
	
	
| 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
 |