WHITESPACE = _{ " " | "\t" | "\n" | "\r" | "\x0B" | "\x0C" | "\xA0" | SPACE_SEPARATOR } COMMENT = _{ ";" ~ (!"\n" ~ ANY)* } assembly = { SOI ~ (origin | include_bin | data | constant | label | instruction)* ~ EOI } origin = { origin_padding | origin_no_padding } origin_padding = { "org.pad" ~ operand_value } origin_no_padding = { "org" ~ operand_value } include_bin = { "#include_bin" ~ immediate_str } data = { data_byte | data_half | data_word | data_str | data_fill } data_byte = { "data.8" ~ operand_value } data_half = { "data.16" ~ operand_value } data_word = { "data.32" ~ operand_value } data_str = { "data.str" ~ immediate_str } data_fill = { "data.fill" ~ operand_value ~ "," ~ operand_value } constant = { "const" ~ constant_name ~ operand_value } constant_name = ${label_name ~ ":"} label = { label_kind? ~ label_name ~ ":" } label_kind = { label_external | label_global } label_name = @{ label_name_chars+ } label_name_chars = @{ ASCII_ALPHANUMERIC | "_" } label_external = { "extern" } label_global = { "global" } operand = { "[" ~ operand_value_ptr ~ "]" | operand_value } operand_value_ptr = { operand_value } operand_value = { register | immediate_bin | immediate_hex | immediate_dec | immediate_char | label_name } size = @{ ".8" | ".16" | ".32" } condition = @{ "ifz" | "ifnz" | "ifc" | "ifnc" | "ifgteq" | "ifgt" | "iflteq" | "iflt" } instruction = { condition? ~ instruction_conditional } instruction_conditional = { instruction_zero | instruction_one ~ size? ~ operand | instruction_two ~ size? ~ operand ~ "," ~ operand } instruction_zero = @{ "nop" | "halt" | "brk" | "reti" | "ret" | "ise" | "icl" | "mse" | "mcl" } instruction_one = @{ "inc" | "dec" | "not" | "jmp" | "call" | "loop" | "rjmp" | "rcall" | "rloop" | "push" | "pop" | "int" | "tlb" | "flp" } instruction_two = @{ "add" | "sub" | "mul" | "div" | "rem" | "and" | "or" | "xor" | "sla" | "sra" | "srl" | "rol" | "ror" | "bse" | "bcl" | "bts" | "cmp" | "movz" | "mov" | "rta" | "in" | "out" } immediate_bin = ${ "0b" ~ body_bin } body_bin = @{ (ASCII_BIN_DIGIT | "_")+ } immediate_hex = ${ "0x" ~ body_hex } body_hex = @{ (ASCII_HEX_DIGIT | "_")+ } immediate_dec = ${ body_dec } body_dec = @{ (ASCII_DIGIT | "_")+ } immediate_char = ${ "'" ~ body_char ~ "'" } body_char = @{ '\x00'..'\x7F' } immediate_str = ${ "\"" ~ body_str ~ "\"" } body_str = @{ body_str_chars* } body_str_chars = { !("\"" | "\\") ~ ANY | "\\" ~ body_str_chars | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4}) } register = ${ "r" ~ register_num } register_num = @{ ASCII_DIGIT+ | "sp" | "esp" }