Add a parser grammar
All checks were successful
Validate the build / validate-build (push) Successful in 24s

Currently this is a subset of the grammar, enough to get reasonable work
going.
This commit is contained in:
omicron 2025-03-31 14:47:58 +02:00
parent 75fc72c35d
commit b4301ed650

36
doc/parser_grammar.txt Normal file
View File

@ -0,0 +1,36 @@
/* string literals are lexer identifier tokens with that particular value */
<program> ::= <statement>*
<statement> ::= ( <label> | <directive> | <instruction> ) <newline>
<label> ::= <identifier> <colon>
<directive> ::= <dot> <section>
<section> ::= "section" <identifier>
<instruction> ::= <identifier> <operands>
<operands> ::= <operand> ( <comma> <operands> )*
<operand> ::= <register> | <immediate> | <memory>
<register> ::= <register_base> | <register_extra>
<register_base> ::= "rax" | "rbx" | "rcx" | "rdx" | "rsi" | "rdi" | "rbp" | "rsp"
<register_extra> ::= "r8" | "r9" | "r10" | "r11" | "r12" | "r13" | "r14" | "r15"
<immediate> ::= <number> | <label_reference>
<number> ::= <octal> | <binary> | <decimal> | <hexadecimal>
<label_reference> ::= <identifier>
<memory> ::= <lbracket> <memory_expression> <rbracket>
<memory_expression> ::= <label_reference> | <register_expression>
<register_expression> ::= <register> ( <plus> <register> <asterisk> <number> )? ( <plus_or_minus> <number> )?
<register_displacement> ::= <plus> <register> <asterisk> <number>
<register_offset> ::= <plus_or_minus> <number>
<plus_or_minus> ::= <plus> | <minus>