1
0
mirror of https://github.com/golang/go synced 2024-11-22 10:14:40 -07:00

goyacc: fix units.y build breakage

This breakage is mainly due to API changes in pkg.
(e.g., package utf8 moved to unicode/utf8;
       remove of strconv.Atof64;
       change character type from int to rune.)
Also correct the usage comment.

This fixes issue 2646.
PS: I don't change the goyacc.go, because I think token type
    should not be force to rune.

R=golang-dev, adg, rogpeppe, r, r
CC=golang-dev
https://golang.org/cl/5502093
This commit is contained in:
Shenghou Ma 2012-01-12 07:54:20 -08:00 committed by Rob Pike
parent 94ff311d1b
commit 26ba35666e

View File

@ -14,7 +14,7 @@
// units.y // units.y
// example of a goyacc program // example of a goyacc program
// usage is // usage is
// goyacc units.y (produces y.go) // goyacc -p "units_" units.y (produces y.go)
// 6g y.go // 6g y.go
// 6l y.6 // 6l y.6
// ./6.out $GOROOT/src/cmd/goyacc/units // ./6.out $GOROOT/src/cmd/goyacc/units
@ -33,7 +33,7 @@ import (
"os" "os"
"math" "math"
"strconv" "strconv"
"utf8" "unicode/utf8"
) )
const ( const (
@ -58,7 +58,7 @@ var lineno int // current input line number
var linep int // index to next rune in unput var linep int // index to next rune in unput
var nerrors int // error count var nerrors int // error count
var one Node // constant one var one Node // constant one
var peekrune int // backup runt from input var peekrune rune // backup runt from input
var retnode1 Node var retnode1 Node
var retnode2 Node var retnode2 Node
var retnode Node var retnode Node
@ -212,7 +212,8 @@ expr0:
type UnitsLex int type UnitsLex int
func (UnitsLex) Lex(yylval *units_SymType) int { func (UnitsLex) Lex(yylval *units_SymType) int {
var c, i int var c rune
var i int
c = peekrune c = peekrune
peekrune = ' ' peekrune = ' '
@ -242,7 +243,7 @@ loop:
yylval.numb = 3 yylval.numb = 3
return SUP return SUP
} }
return c return int(c)
alpha: alpha:
sym = "" sym = ""
@ -267,7 +268,7 @@ numb:
} }
} }
peekrune = c peekrune = c
f, err := strconv.Atof64(sym) f, err := strconv.ParseFloat(sym, 64)
if err != nil { if err != nil {
fmt.Printf("error converting %v\n", sym) fmt.Printf("error converting %v\n", sym)
f = 0 f = 0
@ -362,7 +363,7 @@ func main() {
* all characters that have some * all characters that have some
* meaning. rest are usable as names * meaning. rest are usable as names
*/ */
func ralpha(c int) bool { func ralpha(c rune) bool {
switch c { switch c {
case 0, '+', '-', '*', '/', '[', ']', '(', ')', case 0, '+', '-', '*', '/', '[', ']', '(', ')',
'^', ':', '?', ' ', '\t', '.', '|', '#', '^', ':', '?', ' ', '\t', '.', '|', '#',
@ -375,7 +376,7 @@ func ralpha(c int) bool {
/* /*
* number forming character * number forming character
*/ */
func rdigit(c int) bool { func rdigit(c rune) bool {
switch c { switch c {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'.', 'e', '+', '-': '.', 'e', '+', '-':
@ -577,8 +578,9 @@ func readline() bool {
return false return false
} }
func getrune() int { func getrune() rune {
var c, n int var c rune
var n int
if linep >= len(line) { if linep >= len(line) {
return 0 return 0