in reply to Where does $4 come from here?

What 3 elements? I'm completely guessing, but maybe its cause GRAMPROG expands to
$1 $2 $3 $4 $5 ... %token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT ... or $1 $2 $3 $4
I just stumbled upon Perl 5 Internals by Simon Cozens which talks a bit this in Chapter 5. The Lexer and the Parser

Replies are listed 'Best First'.
Re^2: Where does $4 come from here?
by PerlOnTheWay (Monk) on Jul 27, 2011 at 07:59 UTC
    My understanding is that:

    $1 $2 $3 supposed to refer to the 3 elements on the right of the production.

    While $$ refer to the LHS of the production. But in this production, there're only 3 elements on the right hand side, and I don't see what $4 refers to...

      But in this production, there're only 3 elements on the right hand side, and I don't see what $4 refers to...

      Ok, here is more guessing, if we're talking about GRAMPROG  remember stmtseq and

      remember: /* NULL */ /* start a full lexical scope */ { $$ = block_start(TRUE); } ; stmtseq : /* NULL */ { $$ = (OP*)NULL; } | stmtseq fullstmt { $$ = op_append_list(OP_LINESEQ, $1, $2); PL_pad_reset_pending = TRUE; if ($1 && $2) PL_hints |= HINT_BLOCK_SCOPE; } ;
      then surely $$ = op_append_list(OP_LINESEQ, $1, $2); becomes $2, $3, $4, right?

      :)

        No, that's not how yacc works AFAIK...