Created
January 16, 2019 19:38
-
-
Save 44100hertz/1e6045b0f90d0b3d3f7ff5e71c4fc42b to your computer and use it in GitHub Desktop.
arch256 syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asmfile = @{SOI ~ block ~ EOI} | |
block = @{(line ~ NEWLINE)* ~ line?} | |
WHITESPACE = _{(" " | "\t")+} | |
line = !{ label? ~ (instr | sexpr)? ~ comment? } | |
label = @{ ident ~ ":" } | |
instr = !{ opcode ~ (argument ~ ","?)* } | |
sexpr = !{ "(" ~ expr* ~ ")" } | |
comment = _{ ";" ~ (!NEWLINE ~ ANY)* } | |
ident = @{ !(number | register) ~ ident_inner+ } | |
ident_inner = @{ | |
!(WHITESPACE | NEWLINE | | |
";" | ":" | "(" | ")" | "," | "\"" | ".") ~ ANY | |
} | |
ident_path = {ident ~ ("." ~ ident)*} | |
opcode = @{ASCII_ALPHA{3,8}} | |
argument = {"*"? ~ (register | expr) ~ ","?} | |
register = @{"r" ~ ("1" ~ '0'..'5' | '0'..'9')} | |
block_expr = { "{" ~ block ~ "}" } | |
expr = _{sexpr | block_expr | literal} | |
literal = _{ident_path | number | string} | |
number = ${("+" | "-")? ~ (decimal | "$" ~ hex | "%" ~ binary)} | |
decimal = { ASCII_DIGIT+ } | |
hex = { ASCII_HEX_DIGIT+ } | |
binary = { ("0" | "1" | "_")+ } | |
string = ${ "\"" ~ string_inner ~ "\"" } | |
string_inner = @{ string_char* } | |
string_char = { | |
!("\"" | "\\") ~ ANY | |
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") | |
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment