Commit b5fe0771 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: remove yacc-based parser

- moved yySymType and token constants (L...) to lex.go
- removed oldparser flag and related code
- removed go generate that generated y.go

Fixes #13240.

Change-Id: I2576ec61ee1efe482f2a5132175725c9c02ef977
Reviewed-on: https://go-review.googlesource.com/17176Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent f1b91957
...@@ -627,8 +627,6 @@ var Widthint int ...@@ -627,8 +627,6 @@ var Widthint int
var Widthreg int var Widthreg int
var typesw *Node // TODO(gri) remove when yacc-based parser is gone
var nblank *Node var nblank *Node
var Funcdepth int32 var Funcdepth int32
......
This diff is collapsed.
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:generate go tool yacc go.y
//go:generate go run mkbuiltin.go runtime unsafe //go:generate go run mkbuiltin.go runtime unsafe
package gc package gc
...@@ -203,7 +202,6 @@ func Main() { ...@@ -203,7 +202,6 @@ func Main() {
obj.Flagcount("m", "print optimization decisions", &Debug['m']) obj.Flagcount("m", "print optimization decisions", &Debug['m'])
obj.Flagcount("msan", "build code compatible with C/C++ memory sanitizer", &flag_msan) obj.Flagcount("msan", "build code compatible with C/C++ memory sanitizer", &flag_msan)
obj.Flagcount("newexport", "use new export format", &newexport) // TODO(gri) remove eventually (issue 13241) obj.Flagcount("newexport", "use new export format", &newexport) // TODO(gri) remove eventually (issue 13241)
obj.Flagcount("oldparser", "use old parser", &oldparser) // TODO(gri) remove eventually (issue 13240)
obj.Flagcount("nolocalimports", "reject local (relative) imports", &nolocalimports) obj.Flagcount("nolocalimports", "reject local (relative) imports", &nolocalimports)
obj.Flagstr("o", "write output to `file`", &outfile) obj.Flagstr("o", "write output to `file`", &outfile)
obj.Flagstr("p", "set expected package import `path`", &myimportpath) obj.Flagstr("p", "set expected package import `path`", &myimportpath)
...@@ -318,16 +316,8 @@ func Main() { ...@@ -318,16 +316,8 @@ func Main() {
lexlineno = 1 lexlineno = 1
const BOM = 0xFEFF const BOM = 0xFEFF
// Uncomment the line below to temporarily switch the compiler back
// to the yacc-based parser. Short-term work-around for issues with
// the new recursive-descent parser for which setting -oldparser is
// not sufficient.
// TODO(gri) remove this eventually (issue 13240)
//
// oldparser = 1
for _, infile = range flag.Args() { for _, infile = range flag.Args() {
if trace && Debug['x'] != 0 && oldparser == 0 { if trace && Debug['x'] != 0 {
fmt.Printf("--- %s ---\n", infile) fmt.Printf("--- %s ---\n", infile)
} }
...@@ -844,9 +834,7 @@ func importfile(f *Val, line int) { ...@@ -844,9 +834,7 @@ func importfile(f *Val, line int) {
curio.nlsemi = false curio.nlsemi = false
typecheckok = true typecheckok = true
if oldparser == 0 { push_parser()
push_parser()
}
case 'B': case 'B':
// new export format // new export format
...@@ -867,9 +855,7 @@ func importfile(f *Val, line int) { ...@@ -867,9 +855,7 @@ func importfile(f *Val, line int) {
} }
func unimportfile() { func unimportfile() {
if oldparser == 0 { pop_parser()
pop_parser()
}
if curio.bin != nil { if curio.bin != nil {
obj.Bterm(curio.bin) obj.Bterm(curio.bin)
...@@ -901,9 +887,7 @@ func cannedimports(file string, cp string) { ...@@ -901,9 +887,7 @@ func cannedimports(file string, cp string) {
typecheckok = true typecheckok = true
incannedimport = 1 incannedimport = 1
if oldparser == 0 { push_parser()
push_parser()
}
} }
func isSpace(c int) bool { func isSpace(c int) bool {
...@@ -945,12 +929,64 @@ func isfrog(c int) bool { ...@@ -945,12 +929,64 @@ func isfrog(c int) bool {
return false return false
} }
type Loophack struct { type yySymType struct {
next *Loophack yys int
v bool node *Node
list *NodeList
typ *Type
sym *Sym
val Val
i int
} }
var _yylex_lstk *Loophack const (
LLITERAL = 57346 + iota
LASOP
LCOLAS
LBREAK
LCASE
LCHAN
LCONST
LCONTINUE
LDDD
LDEFAULT
LDEFER
LELSE
LFALL
LFOR
LFUNC
LGO
LGOTO
LIF
LIMPORT
LINTERFACE
LMAP
LNAME
LPACKAGE
LRANGE
LRETURN
LSELECT
LSTRUCT
LSWITCH
LTYPE
LVAR
LANDAND
LANDNOT
LBODY
LCOMM
LDEC
LEQ
LGE
LGT
LIGNORE
LINC
LLE
LLSH
LLT
LNE
LOROR
LRSH
)
func _yylex(yylval *yySymType) int32 { func _yylex(yylval *yySymType) int32 {
var c1 int var c1 int
...@@ -958,7 +994,6 @@ func _yylex(yylval *yySymType) int32 { ...@@ -958,7 +994,6 @@ func _yylex(yylval *yySymType) int32 {
var v int64 var v int64
var cp *bytes.Buffer var cp *bytes.Buffer
var s *Sym var s *Sym
var h *Loophack
var str string var str string
prevlineno = lineno prevlineno = lineno
...@@ -1367,61 +1402,6 @@ l0: ...@@ -1367,61 +1402,6 @@ l0:
goto asop goto asop
} }
// clumsy dance:
// to implement rule that disallows
// if T{1}[0] { ... }
// but allows
// if (T{1}[0]) { ... }
// the block bodies for if/for/switch/select
// begin with an LBODY token, not '{'.
//
// when we see the keyword, the next
// non-parenthesized '{' becomes an LBODY.
// loophack is normally false.
// a keyword sets it to true.
// parens push loophack onto a stack and go back to false.
// a '{' with loophack == true becomes LBODY and disables loophack.
//
// I said it was clumsy.
//
// We only need the loophack when running with -oldparser.
case '(', '[':
if oldparser != 0 && (loophack || _yylex_lstk != nil) {
h = new(Loophack)
if h == nil {
Flusherrors()
Yyerror("out of memory")
errorexit()
}
h.v = loophack
h.next = _yylex_lstk
_yylex_lstk = h
loophack = false
}
goto lx
case ')', ']':
if oldparser != 0 && _yylex_lstk != nil {
h = _yylex_lstk
loophack = h.v
_yylex_lstk = h.next
}
goto lx
case '{':
if oldparser != 0 && loophack {
if Debug['x'] != 0 {
fmt.Printf("%v lex: LBODY\n", Ctxt.Line(int(lexlineno)))
}
loophack = false
return LBODY
}
goto lx
default: default:
goto lx goto lx
} }
...@@ -1485,14 +1465,8 @@ talph: ...@@ -1485,14 +1465,8 @@ talph:
ungetc(c) ungetc(c)
s = LookupBytes(lexbuf.Bytes()) s = LookupBytes(lexbuf.Bytes())
switch s.Lexical { if s.Lexical == LIGNORE {
case LIGNORE:
goto l0 goto l0
case LFOR, LIF, LSWITCH, LSELECT:
if oldparser != 0 {
loophack = true // see comment about loophack above
}
} }
if Debug['x'] != 0 { if Debug['x'] != 0 {
...@@ -1934,18 +1908,11 @@ func (yy) Error(msg string) { ...@@ -1934,18 +1908,11 @@ func (yy) Error(msg string) {
Yyerror("%s", msg) Yyerror("%s", msg)
} }
var oldparser int // if set, theparser is used (otherwise we use the recursive-descent parser)
var theparser yyParser
var parsing bool var parsing bool
func yyparse() { func yyparse() {
parsing = true parsing = true
if oldparser != 0 { parse_file()
theparser = yyNewParser()
theparser.Parse(yy{})
} else {
parse_file()
}
parsing = false parsing = false
} }
...@@ -2617,20 +2584,6 @@ var yytfix = map[string]string{ ...@@ -2617,20 +2584,6 @@ var yytfix = map[string]string{
"','": "comma", "','": "comma",
} }
func init() {
yyErrorVerbose = true
for i, s := range yyToknames {
// Apply yytfix if possible.
if fix, ok := yytfix[s]; ok {
yyToknames[i] = fix
} else if len(s) == 3 && s[0] == '\'' && s[2] == '\'' {
// Turn 'x' into x.
yyToknames[i] = s[1:2]
}
}
}
func pkgnotused(lineno int, path string, name string) { func pkgnotused(lineno int, path string, name string) {
// If the package was imported with a name other than the final // If the package was imported with a name other than the final
// import path element, show it explicitly in the error message. // import path element, show it explicitly in the error message.
......
...@@ -229,55 +229,52 @@ func tokstring(tok int32) string { ...@@ -229,55 +229,52 @@ func tokstring(tok int32) string {
} }
var tokstrings = map[int32]string{ var tokstrings = map[int32]string{
LLITERAL: "LLITERAL", LLITERAL: "LLITERAL",
LASOP: "op=", LASOP: "op=",
LCOLAS: ":=", LCOLAS: ":=",
LBREAK: "break", LBREAK: "break",
LCASE: "case", LCASE: "case",
LCHAN: "chan", LCHAN: "chan",
LCONST: "const", LCONST: "const",
LCONTINUE: "continue", LCONTINUE: "continue",
LDDD: "...", LDDD: "...",
LDEFAULT: "default", LDEFAULT: "default",
LDEFER: "defer", LDEFER: "defer",
LELSE: "else", LELSE: "else",
LFALL: "fallthrough", LFALL: "fallthrough",
LFOR: "for", LFOR: "for",
LFUNC: "func", LFUNC: "func",
LGO: "go", LGO: "go",
LGOTO: "goto", LGOTO: "goto",
LIF: "if", LIF: "if",
LIMPORT: "import", LIMPORT: "import",
LINTERFACE: "interface", LINTERFACE: "interface",
LMAP: "map", LMAP: "map",
LNAME: "LNAME", LNAME: "LNAME",
LPACKAGE: "package", LPACKAGE: "package",
LRANGE: "range", LRANGE: "range",
LRETURN: "return", LRETURN: "return",
LSELECT: "select", LSELECT: "select",
LSTRUCT: "struct", LSTRUCT: "struct",
LSWITCH: "switch", LSWITCH: "switch",
LTYPE: "type", LTYPE: "type",
LVAR: "var", LVAR: "var",
LANDAND: "&&", LANDAND: "&&",
LANDNOT: "&^", LANDNOT: "&^",
LBODY: "LBODY", // we should never see this one LBODY: "LBODY", // we should never see this one
LCOMM: "<-", LCOMM: "<-",
LDEC: "--", LDEC: "--",
LEQ: "==", LEQ: "==",
LGE: ">=", LGE: ">=",
LGT: ">", LGT: ">",
LIGNORE: "LIGNORE", // we should never see this one LIGNORE: "LIGNORE", // we should never see this one
LINC: "++", LINC: "++",
LLE: "<=", LLE: "<=",
LLSH: "<<", LLSH: "<<",
LLT: "<", LLT: "<",
LNE: "!=", LNE: "!=",
LOROR: "||", LOROR: "||",
LRSH: ">>", LRSH: ">>",
NotPackage: "NotPackage", // we should never see this one
NotParen: "NotParen", // we should never see this one
PreferToRightParen: "PreferToRightParen", // we should never see this one
} }
// usage: defer p.trace(msg)() // usage: defer p.trace(msg)()
......
...@@ -34,10 +34,6 @@ func errorexit() { ...@@ -34,10 +34,6 @@ func errorexit() {
} }
func parserline() int { func parserline() int {
if oldparser != 0 && parsing && theparser.Lookahead() > 0 {
// parser has one symbol lookahead
return int(prevlineno)
}
return int(lineno) return int(lineno)
} }
......
This diff is collapsed.
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