Bison parser exhibiting weird behavior

Fr <[email protected]> Sat, 6 Sep 2025 11:01:47 +0200
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
Hello, everyone.

I am currently working on a Yacc parser, using GNU Bison. I have the 
following grammar rules:

block_list:
     block_expr '\n'
     {$$ = new_expression(exprBlock, 1, $1);}
   | block_list block_expr '\n'
     {expression_add_child($1, $2);
      $$ = $1;
     }
   ;

With new_expression creating an expression with the exprBlock type. Yet 
the following assertion in expression_add_child fails :

assert(expr->type == exprBlock); // expr is $1

An extract of the verbose Bison output, with the assertion failure :

Next token is token '\n' ()
Shifting token '\n' ()
Entering state 97
Stack now 0 2 7 12 31 69 97
Reducing stack by rule 17 (line 115):
    $1 = nterm block_list ()
    $2 = nterm block_expr ()
    $3 = token '\n' ()
flang: src/parser_utils.c:158: expression_add_child: Assertion 
`expr->type == exprBlock' failed.

Upon inspection with GDB, it seems like when the assertion fails, $1 is 
of type exprVar (a possible expression type for a block_expr) and more 
surprisingly, $1 == $2

I am on Debian 12, and the output of bison -V is the following :

bison (GNU Bison) 3.8.2

Thank you in advance.