I am writing code in bison that parses various assembly instruction. Here is a tidbit:
text
: text NEWLINE Instruction
| Instruction
;
Instruction
: r-type
{
instruction.format = IF_R;
instruction.opcode = 0b0110011;
}
;
r-type
: add
{
instruction.funct3 = 0x0;
instruction.funct7 = 0x00;
}
;
add
: ADD REGISTER COMMA REGISTER COMMA REGISTER
{
instruction.rd = $2;
instruction.rs1 = $4;
instruction.rs2 = $6;
}
;
Assume that instruction (lowercase) is a struct, and the (ALL CAPS) tokens are received from a lexer.
Does the 'add' non-terminal need to have a grammar rule that says $$ = *something*; or is this set up fine. Also is it fine to have multiple semantic rules along the token chain?
I have tried getting help from AI. It says that the non-terminal nodes are not defined. and the way that I write my semantic tokens is not standard. the rest of it is nonsense jargon.