]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/yacc: adjust expansion of $n to be more useful in errors
authorRuss Cox <rsc@golang.org>
Fri, 6 Feb 2015 18:48:42 +0000 (13:48 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 13 Feb 2015 17:29:36 +0000 (17:29 +0000)
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>
src/cmd/yacc/yacc.go

index 0a69c36afc0018858acce7189faed5816bf1512b..24692dc1665e95a152fc19a0bd508eda13ed7f80 100644 (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 */