x/tools/cmd/goyacc: When growing the stack, save it in the parser #16163
Labels
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
go version
)?go env
)?I wrote a Yacc parser for parsing shell commands into an AST.
I accessed the resulting AST via
yyParserImpl.stack[1]
.For small examples, this worked well.
More complicated examples resulted in
nil
being on the stack.yyParserImpl.stack[1]
should always contain the result, no matter how deeply nested the grammar is.When the Yacc parser needs more stack, it grows it. The code is after the
yystack:
label. This new stack is then local to the current function, and it is not written back into the parser. This means that callingParse
multiple times will create unnecessary copies of the stack. And, more importantly, accessing the actual stack becomes impossible.References: http://stackoverflow.com/questions/36822702/accessing-result-of-a-golang-yacc-generated-parser
The text was updated successfully, but these errors were encountered: