1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:14:43 -07:00

cmd/yacc: adjust expansion of $n to be more useful in errors

When the compiler echoes back an expression, it shows the
generated yacc expression. Change the generated code to
use a slice so that $3 shows up as yyDollar[3] in such messages.

Consider changing testdata/expr/expr.y to say:

	$$.Sub(float64($1), $3)

(The float64 conversion is incorrect.)

Before:
expr.y:70[expr.go:486]: cannot convert exprS[exprpt - 2].num (type *big.Rat) to type float64

After:
expr.y:70[expr.go:492]: cannot convert exprDollar[1].num (type *big.Rat) to type float64

Change-Id: I74e494069df588e62299d1fccb282f3658d8f8f4
Reviewed-on: https://go-review.googlesource.com/4630
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Russ Cox 2015-02-06 13:48:42 -05:00
parent 3be158d6ab
commit 2e78447baf

View File

@ -603,6 +603,7 @@ outer:
}
levprd[nprod] |= ACTFLAG
fmt.Fprintf(fcode, "\n\tcase %v:", nprod)
fmt.Fprintf(fcode, "\n\t\t%sDollar = %sS[%spt-%v:%spt+1]", prefix, prefix, prefix, mem-1, prefix)
cpyact(curprod, mem)
// action within rule...
@ -1345,7 +1346,7 @@ loop:
ungetrune(finput, c)
continue loop
}
fmt.Fprintf(fcode, "%sS[%spt-%v]", prefix, prefix, max-j-1)
fmt.Fprintf(fcode, "%sDollar[%v]", prefix, j)
// put out the proper tag
if ntypes != 0 {
@ -3264,6 +3265,7 @@ func $$Parse($$lex $$Lexer) int {
var $$n int
var $$lval $$SymType
var $$VAL $$SymType
var $$Dollar []$$SymType
$$S := make([]$$SymType, $$MaxDepth)
Nerrs := 0 /* number of errors */