No, access to stack[1] does not work reliably. It does not contain any result, as soon as the stack should grow above 16, its original size. (See # 16163. )
The if after the yystack label creates a new stack and completely forgets about the one that was saved in yyParserImpl .
I did the following.
Add the result field to the lexer type:
type ShellLexer struct { result *ShellProgram }
First expand the grammar with the following rule:
start : program { shyylex.(*ShellLexer).result = $$ }
(It depends on the parameter name of the Parse method (which may have its own prefix), but I think this is normal.)
source share