diff options
author | sanine <sanine.not@pm.me> | 2023-05-22 23:43:39 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-22 23:43:39 -0500 |
commit | c1709249728cb9ad7011b0d39d18ad87d4636f4b (patch) | |
tree | d4fae900af8cc4ee2956bbbe3c5c70c1664b193f /src/parser/grammar.jison | |
parent | d6e89d16d332954dde3fc4c5ee7549af7c8bb556 (diff) |
begin testing and make grammar more spec-compliant
Diffstat (limited to 'src/parser/grammar.jison')
-rw-r--r-- | src/parser/grammar.jison | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/src/parser/grammar.jison b/src/parser/grammar.jison index edcca5c..4f4a433 100644 --- a/src/parser/grammar.jison +++ b/src/parser/grammar.jison @@ -110,46 +110,80 @@ row op - : opcode address "," address - { $$ = { opcode: $opcode, a: $address1, b: $address2 }; } - | opcode address - { + : op_immediate_a { $$ = $1; } + | op_immediate_b { $$ = $1; } + | DAT dat_addr "," dat_addr { $$ = { opcode: $1, a: $dat_addr1, b: $dat_addr2 }; } + | DAT dat_addr { $$ = { opcode: $1, a: $dat_addr1, b: { mode: 'immediate', value: 0 } }; } + ; + + +op_immediate_a + : opcode_immediate_a address "," non_immediate_addr + { $$ = { opcode: $1, a: $2, b: $4 }; } + ; + +op_immediate_b + : opcode_immediate_b non_immediate_addr "," address + { $$ = { opcode: $1, a: $2, b: $4 }; } + | opcode_immediate_b non_immediate_addr + { $$ = { - opcode: $opcode, - a: $address, + opcode: $1, + a: $2, b: { mode: 'direct', value: 0 }, }; } ; -opcode + +opcode_immediate_a : MOV { $$ = $1; } | ADD { $$ = $1; } | SUB { $$ = $1; } | CMP { $$ = $1; } | SLT { $$ = $1; } - | JMP { $$ = $1; } + ; +opcode_immediate_b + : JMP { $$ = $1; } | JMZ { $$ = $1; } | JMN { $$ = $1; } | DJN { $$ = $1; } | SPL { $$ = $1; } - | DAT { $$ = $1; } ; address - : address_mode e { $$ = { mode: $1, value: $2 }; } - | e { $$ = { mode: 'direct', value: $1 }; } + : immediate_addr { $$ = $1; } + | non_immediate_addr { $$ = $1; } ; -address_mode - : "#" { $$ = 'immediate'; } - | "@" { $$ = 'indirect'; } - | "<" { $$ = 'predecrement'; } - | "$" { $$ = 'direct'; } +non_immediate_addr + : direct_addr { $$ = $1; } + | indirect_addr { $$ = $1; } + | predecrement_addr { $$ = $1; } ; +dat_addr + : immediate_addr { $$ = $1; } + | predecrement_addr { $$ = $1; } + ; + +immediate_addr + : "#" e { $$ = { mode: 'immediate', value: $e }; } + ; +direct_addr + : "$" e { $$ = { mode: 'direct', value: $e }; } + | e { $$ = { mode: 'direct', value: $e }; } + ; +indirect_addr + : "@" e { $$ = { mode: 'indirect', value: $e }; } + ; +predecrement_addr + : "<" e { $$ = { mode: 'predecrement', value: $e }; } + ; + + e |