Files
hm-asm/src/asm.pest
2020-11-30 18:28:25 +01:00

31 lines
842 B
Plaintext

program = _{ SOI ~ "\n"* ~ (stmt ~ "\n"+) * ~ stmt? ~ EOI }
stmt = { ((label ~ ":")? ~ instruction)}
instruction = {
no_arg_instruction |
arg_instruction ~ argument |
jump_instruction ~ jump_argument |
memory_location_instruction ~ memory_location |
constant_arg_instruction ~ digit_literal
}
memory_location_instruction = {"STA"}
constant_arg_instruction = {"BRZ" | "BRC" | "BRN"}
jump_instruction = {"JMP"}
arg_instruction = {"LDA" | "ADD" | "SUB"}
no_arg_instruction = { "NOP" }
jump_argument = { jump_location | label | memory_location }
argument = { memory_location | digit_literal }
memory_location = { "(" ~ ASCII_HEX_DIGIT ~")" }
digit_literal = {"#" ~ ASCII_HEX_DIGIT}
jump_location = { '0'..'9' | 'a'..'f' }
label = { ASCII_ALPHA_UPPER+ }
WHITESPACE = _{ " " | "\t" }
COMMENT = _{"//" ~ (!"\n" ~ ANY)* }