With a few additions, I get the same result you did, but this grammar,
while it is LR(2), is not LR(1) or LALR(1). Suppose that the input
contains
MOV @ R 3 , #
At the crucial point, we'll have
MOV @ R ireg
on the stack (right end is top) and "," as the lookahead. This is not
enough data to decide whether to reduce to ireg_MOVE_INDIRECT_DIRECT,
ireg_MOVE_INDIRECT_A, or ireg_MOVE_INDIRECT_DATA.
Paul Hilfinger
%term const_num
%%
inst: MOVE_INDIRECT_DIRECT | MOVE_INDIRECT | MOVE_INDIRECT_DATA ;
MOVE_INDIRECT_DIRECT: "MOV" "@" "R" ireg_MOVE_INDIRECT_DIRECT ","
dir_MOVE_INDIRECT_DIRECT
{
...
};
MOVE_INDIRECT: "MOV" "@" "R" ireg_MOVE_INDIRECT_A "," "A"
{
...
};
MOVE_INDIRECT_DATA: "MOV" "@" "R" ireg_MOVE_INDIRECT_DATA "," "#"
data_MOVE_INDIRECT_DATA
{
...
};
ireg_MOVE_INDIRECT_DIRECT: ireg
{
$$ = $1;
};
ireg_MOVE_INDIRECT_A: ireg
{
$$ = $1;
};
ireg_MOVE_INDIRECT_DATA: ireg
{
$$ = $1;
};
dir_MOVE_INDIRECT_DIRECT: byte
{
$$ = $1;
};
data_MOVE_INDIRECT_DATA: byte
{
$$ = $1;
};
ireg: const_num //decadical value from lex
{
...
};
byte: const_num //decadical value from lex
{
...
};
%%