为什么在定义更多类型时,Go的yacc解析器会出现panic错误?

huangapple go评论76阅读模式
英文:

why does go yacc parser panic while defining more types?

问题

我用更多类型编写了一个名为test.y的文件。在达到一定限制后,当我使用命令编译该文件时,出现了错误信息:"Index out of range in yacc.go:891"。当我查看文件https://golang.org/src/cmd/yacc/yacc.go时,在定义常量时看到了以下注释:"根据内存大小可调整以下内容"。是否有特定原因导致他们在该文件中的第74行将类型定义的数量限制为63(NTYPES = 63)?

英文:

I wrote a test.y file with more types. After certain limit, when I compiled the file with command,
go tool yacc test

It panics,"Index out of range in yacc.go:891"
When I looked at the file https://golang.org/src/cmd/yacc/yacc.go, I saw this comment in defining the constants
"the following are adjustable according to memory size"
Is there a reason why they have limited the number of type definition to 63(NTYPES = 63) in line 74(in the file mentioned in the link above)

答案1

得分: 1

有趣的是,我经常使用go tool yacc,但没有注意到这个限制。

之所以这样是因为yacc.go是从一个C程序移植过来的,你看到的就是显而易见的直接移植。

看一下yacc.go的代码,很容易去除这个限制,并将typeset数组转换为切片。

我会这样做:打开一个问题(检查一下是否已经存在一个问题 - 我没有看到一个,但我没有仔细查看)。接下来,如果你有勇气,可以使用go贡献指南提交一个补丁。这是参与go本身贡献的好方法。

英文:

Interesting - I've used go tool yacc quite a bit and not noticed this limitation.

The reason it is like that is that yacc.go was ported from a C program and what you see is the obvious straight forward port.

Looking at the code of yacc.go it would be very straightforward to remove that limitation and turn the typeset array into a slice.

What I would do is open an issue (check a that there isn't an existing one - I didn't see one but I didn't look very carefully). Next if you are feeling brave submit a patch using the go contribution guidelines. It is a good way to get into contributing to go itself.

答案2

得分: 1

"它发生了恐慌,yacc.go:891处的索引超出范围错误。"

我遇到了同样的问题,因为我需要更多的类型(非终结符和终结符类型),为了解决我的问题,我改变了几个值。

请查看我GitHub页面上记录了我的更改

或者直接点击下面的URL。

https://github.com/MagnusTiberius/go/commit/d4eeb860229867c76d99e67d69bdbd7cc729ce2c

英文:

"It panics,"Index out of range in yacc.go:891" "

I got into the same problem because I needed more types (non-term and term types) and what I did to remedy my situation was to change several values.

Please see my GitHub page documenting my change.

Or simply click on the URL below.

https://github.com/MagnusTiberius/go/commit/d4eeb860229867c76d99e67d69bdbd7cc729ce2c

huangapple
  • 本文由 发表于 2015年2月17日 14:10:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/28555766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定