Commit 2e78447b authored by Russ Cox's avatar Russ Cox

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/4630Reviewed-by: 's avatarRob Pike <r@golang.org>
parent 3be158d6
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment