Commit 0826c04e authored by Russ Cox's avatar Russ Cox

cmd/yacc: report correct line for 'default action causes potential type clash'

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13588044
parent 8ce9a4fd
...@@ -555,17 +555,18 @@ outer: ...@@ -555,17 +555,18 @@ outer:
// process a rule // process a rule
rlines[nprod] = lineno rlines[nprod] = lineno
ruleline := lineno
if t == '|' { if t == '|' {
curprod[mem] = prdptr[nprod-1][0] curprod[mem] = prdptr[nprod-1][0]
mem++ mem++
} else if t == IDENTCOLON { } else if t == IDENTCOLON {
curprod[mem] = chfind(1, tokname) curprod[mem] = chfind(1, tokname)
if curprod[mem] < NTBASE { if curprod[mem] < NTBASE {
errorf("token illegal on LHS of grammar rule") lerrorf(ruleline, "token illegal on LHS of grammar rule")
} }
mem++ mem++
} else { } else {
errorf("illegal rule: missing semicolon or | ?") lerrorf(ruleline, "illegal rule: missing semicolon or | ?")
} }
// read rule body // read rule body
...@@ -586,11 +587,11 @@ outer: ...@@ -586,11 +587,11 @@ outer:
} }
if t == PREC { if t == PREC {
if gettok() != IDENTIFIER { if gettok() != IDENTIFIER {
errorf("illegal %%prec syntax") lerrorf(ruleline, "illegal %%prec syntax")
} }
j = chfind(2, tokname) j = chfind(2, tokname)
if j >= NTBASE { if j >= NTBASE {
errorf("nonterminal " + nontrst[j-NTBASE].name + " illegal after %%prec") lerrorf(ruleline, "nonterminal "+nontrst[j-NTBASE].name+" illegal after %%prec")
} }
levprd[nprod] = toklev[j] levprd[nprod] = toklev[j]
t = gettok() t = gettok()
...@@ -646,7 +647,7 @@ outer: ...@@ -646,7 +647,7 @@ outer:
// no explicit action, LHS has value // no explicit action, LHS has value
tempty := curprod[1] tempty := curprod[1]
if tempty < 0 { if tempty < 0 {
errorf("must return a value, since LHS has a type") lerrorf(ruleline, "must return a value, since LHS has a type")
} }
if tempty >= NTBASE { if tempty >= NTBASE {
tempty = nontrst[tempty-NTBASE].value tempty = nontrst[tempty-NTBASE].value
...@@ -654,7 +655,7 @@ outer: ...@@ -654,7 +655,7 @@ outer:
tempty = TYPE(toklev[tempty]) tempty = TYPE(toklev[tempty])
} }
if tempty != nontrst[curprod[0]-NTBASE].value { if tempty != nontrst[curprod[0]-NTBASE].value {
errorf("default action causes potential type clash") lerrorf(ruleline, "default action causes potential type clash")
} }
fmt.Fprintf(fcode, "\n\tcase %v:", nprod) fmt.Fprintf(fcode, "\n\tcase %v:", nprod)
fmt.Fprintf(fcode, "\n\t\t%sVAL.%v = %sS[%spt-0].%v", fmt.Fprintf(fcode, "\n\t\t%sVAL.%v = %sS[%spt-0].%v",
...@@ -3193,7 +3194,7 @@ func create(s string) *bufio.Writer { ...@@ -3193,7 +3194,7 @@ func create(s string) *bufio.Writer {
// //
// write out error comment // write out error comment
// //
func errorf(s string, v ...interface{}) { func lerrorf(lineno int, s string, v ...interface{}) {
nerrors++ nerrors++
fmt.Fprintf(stderr, s, v...) fmt.Fprintf(stderr, s, v...)
fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno) fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno)
...@@ -3203,6 +3204,10 @@ func errorf(s string, v ...interface{}) { ...@@ -3203,6 +3204,10 @@ func errorf(s string, v ...interface{}) {
} }
} }
func errorf(s string, v ...interface{}) {
lerrorf(lineno, s, v...)
}
func exit(status int) { func exit(status int) {
if ftable != nil { if ftable != nil {
ftable.Flush() ftable.Flush()
......
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