Skip to contentSkip to conversation

shift_stmt_expr grammar question

DISCUSSION Jeremy Sowden 2 participants 2 messages Mar 8, 2020 – Mar 9, 2020 netfilter

lore
Share & tools
lore
#0 lore raw

Just noticed that the production for right shifts differs from the production for left shifts (src/parser_bison.y, ll. 3020ff.):

  shift_stmt_expr    :       primary_stmt_expr
                     |       shift_stmt_expr         LSHIFT          primary_stmt_expr
                     {
                             $$ = binop_expr_alloc(&@$, OP_LSHIFT, $1, $3);
                     }
                     |       shift_stmt_expr         RSHIFT          primary_rhs_expr
                     {
                             $$ = binop_expr_alloc(&@$, OP_RSHIFT, $1, $3);
                     }
                     ;

Is there a reason why the RHS of LSHIFT is primary_stmt_expr, but the RHS of RSHIFT is primary_rhs_expr?

J.

#1 lore raw

Hi Jeremy,

Quoted 14 lines · Jeremy Sowden

Just noticed that the production for right shifts differs from the production for left shifts (src/parser_bison.y, ll. 3020ff.):

  shift_stmt_expr    :       primary_stmt_expr
                     |       shift_stmt_expr         LSHIFT          primary_stmt_expr
                     {
                             $$ = binop_expr_alloc(&@$, OP_LSHIFT, $1, $3);
                     }
                     |       shift_stmt_expr         RSHIFT          primary_rhs_expr
                     {
                             $$ = binop_expr_alloc(&@$, OP_RSHIFT, $1, $3);
                     }
                     ;
Quoted 2 lines

Is there a reason why the RHS of LSHIFT is primary_stmt_expr, but the RHS of RSHIFT is primary_rhs_expr?

It's likely a leftover. The rhs rule was introduced to reduce chances of hitting shift/reduce conflicts, and to restrict syntax on the rhs.