Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/goyacc: When growing the stack, save it in the parser #16163

Open
rillig opened this issue Jun 23, 2016 · 3 comments
Open

x/tools/cmd/goyacc: When growing the stack, save it in the parser #16163

rillig opened this issue Jun 23, 2016 · 3 comments
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@rillig
Copy link
Contributor

rillig commented Jun 23, 2016

  1. What version of Go are you using (go version)?
go version go1.6.2 windows/amd64
  1. What operating system and processor architecture are you using (go env)?
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\rillig\go
set GORACE=
set GOROOT=C:\Program Files (x86)\Go1.6.2
set GOTOOLDIR=C:\Program Files (x86)\Go1.6.2\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
  1. What did you do?

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.

  1. What did you expect to see?

yyParserImpl.stack[1] should always contain the result, no matter how deeply nested the grammar is.

  1. What did you see instead?

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 calling Parse 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

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 23, 2016
@ianlancetaylor
Copy link
Contributor

It would help a great deal to have a test case showing the problem. Thanks.

@rillig
Copy link
Contributor Author

rillig commented Jun 23, 2016

issue16163.zip

The grammar implements a simple counter. Some grammar productions need a stack longer than the default initial size. Starting with 16, a new stack gets allocated, which then results in unexpected values being stored in stack[1].

rillig added a commit to rillig/go-yacc-examples that referenced this issue Jul 24, 2016
@bradfitz bradfitz modified the milestones: Unreleased, Go1.8 Sep 25, 2016
@bradfitz bradfitz changed the title cmd/yacc: When growing the stack, save it in the parser x/tools/cmd/yacc: When growing the stack, save it in the parser Sep 25, 2016
@bradfitz bradfitz changed the title x/tools/cmd/yacc: When growing the stack, save it in the parser x/tools/cmd/goyacc: When growing the stack, save it in the parser Sep 25, 2016
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
@gopherbot
Copy link

Change https://go.dev/cl/424776 mentions this issue: cmd/goyacc: save stack in parser after resizing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants