mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/yacc: fix handling of tokens that don't start with letters
CL 149110043 changed yacc to no longer keep a leading space for quoted tokens. That is OK by itself but unfortunately yacc was relying on that leading space to notice which tokens it should not output as const declarations. Add a few such tokens to expr.y, although it won't make any immediate difference as we seem to have no tests for yacc. LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://golang.org/cl/152720043
This commit is contained in:
parent
1cfa5958f0
commit
fe2bc11e1f
2 changed files with 11 additions and 5 deletions
2
src/cmd/yacc/testdata/expr/expr.y
vendored
2
src/cmd/yacc/testdata/expr/expr.y
vendored
|
|
@ -32,6 +32,8 @@ import (
|
||||||
|
|
||||||
%type <num> expr expr1 expr2 expr3
|
%type <num> expr expr1 expr2 expr3
|
||||||
|
|
||||||
|
%token '+' '-' '*' '/' '(' ')'
|
||||||
|
|
||||||
%token <num> NUM
|
%token <num> NUM
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
|
||||||
|
|
@ -195,8 +195,9 @@ type Item struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Symb struct {
|
type Symb struct {
|
||||||
name string
|
name string
|
||||||
value int
|
noconst bool
|
||||||
|
value int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Wset struct {
|
type Wset struct {
|
||||||
|
|
@ -509,8 +510,7 @@ outer:
|
||||||
// put out non-literal terminals
|
// put out non-literal terminals
|
||||||
for i := TOKSTART; i <= ntokens; i++ {
|
for i := TOKSTART; i <= ntokens; i++ {
|
||||||
// non-literals
|
// non-literals
|
||||||
c := tokset[i].name[0]
|
if !tokset[i].noconst {
|
||||||
if c != ' ' && c != '$' {
|
|
||||||
fmt.Fprintf(ftable, "const %v = %v\n", tokset[i].name, tokset[i].value)
|
fmt.Fprintf(ftable, "const %v = %v\n", tokset[i].name, tokset[i].value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -734,7 +734,7 @@ func defin(nt int, s string) int {
|
||||||
copy(anontrst, nontrst)
|
copy(anontrst, nontrst)
|
||||||
nontrst = anontrst
|
nontrst = anontrst
|
||||||
}
|
}
|
||||||
nontrst[nnonter] = Symb{s, 0}
|
nontrst[nnonter] = Symb{name: s}
|
||||||
return NTBASE + nnonter
|
return NTBASE + nnonter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -769,9 +769,13 @@ func defin(nt int, s string) int {
|
||||||
if val == 0 {
|
if val == 0 {
|
||||||
errorf("token value 0 is illegal")
|
errorf("token value 0 is illegal")
|
||||||
}
|
}
|
||||||
|
tokset[ntokens].noconst = true
|
||||||
} else {
|
} else {
|
||||||
val = extval
|
val = extval
|
||||||
extval++
|
extval++
|
||||||
|
if s[0] == '$' {
|
||||||
|
tokset[ntokens].noconst = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tokset[ntokens].value = val
|
tokset[ntokens].value = val
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue