Commit 8fd7c11d authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: delete unused lexer tokens, replace with LOPER

Also: Use same ordering of tokens in the various tables/maps.

Change-Id: Ief84c6ca3da36213ace6b2c10b513e2ca16318ab
Reviewed-on: https://go-review.googlesource.com/20110
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 59681802
...@@ -892,7 +892,7 @@ type lexer struct { ...@@ -892,7 +892,7 @@ type lexer struct {
tok int32 tok int32
sym_ *Sym // valid if tok == LNAME sym_ *Sym // valid if tok == LNAME
val Val // valid if tok == LLITERAL val Val // valid if tok == LLITERAL
op Op // valid if tok == LASOP or LINCOP, or prec > 0 op Op // valid if tok == LOPER, LASOP, or LINCOP, or prec > 0
prec OpPrec // operator precedence; 0 if not a binary operator prec OpPrec // operator precedence; 0 if not a binary operator
} }
...@@ -911,15 +911,27 @@ const ( ...@@ -911,15 +911,27 @@ const (
const ( const (
// The value of single-char tokens is just their character's Unicode value. // The value of single-char tokens is just their character's Unicode value.
// They are all below utf8.RuneSelf. Shift other tokens up to avoid conflicts. // They are all below utf8.RuneSelf. Shift other tokens up to avoid conflicts.
LLITERAL = utf8.RuneSelf + iota
// names and literals
LNAME = utf8.RuneSelf + iota
LLITERAL
// operator-based operations
LOPER
LASOP LASOP
LINCOP
// miscellaneous
LCOLAS LCOLAS
LCOMM
LDDD
// keywords
LBREAK LBREAK
LCASE LCASE
LCHAN LCHAN
LCONST LCONST
LCONTINUE LCONTINUE
LDDD
LDEFAULT LDEFAULT
LDEFER LDEFER
LELSE LELSE
...@@ -932,7 +944,6 @@ const ( ...@@ -932,7 +944,6 @@ const (
LIMPORT LIMPORT
LINTERFACE LINTERFACE
LMAP LMAP
LNAME
LPACKAGE LPACKAGE
LRANGE LRANGE
LRETURN LRETURN
...@@ -941,20 +952,8 @@ const ( ...@@ -941,20 +952,8 @@ const (
LSWITCH LSWITCH
LTYPE LTYPE
LVAR LVAR
LANDAND
LANDNOT
LCOMM
LEQ
LGE
LGT
LIGNORE LIGNORE
LINCOP
LLE
LLSH
LLT
LNE
LOROR
LRSH
) )
func (l *lexer) next() { func (l *lexer) next() {
...@@ -1119,9 +1118,9 @@ l0: ...@@ -1119,9 +1118,9 @@ l0:
goto incop goto incop
case '>': case '>':
c = LOPER
c1 = l.getr() c1 = l.getr()
if c1 == '>' { if c1 == '>' {
c = LRSH
op = ORSH op = ORSH
prec = PMUL prec = PMUL
goto binop goto binop
...@@ -1129,17 +1128,15 @@ l0: ...@@ -1129,17 +1128,15 @@ l0:
l.prec = PCMP l.prec = PCMP
if c1 == '=' { if c1 == '=' {
c = LGE
l.op = OGE l.op = OGE
goto lx goto lx
} }
c = LGT
l.op = OGT l.op = OGT
case '<': case '<':
c = LOPER
c1 = l.getr() c1 = l.getr()
if c1 == '<' { if c1 == '<' {
c = LLSH
op = OLSH op = OLSH
prec = PMUL prec = PMUL
goto binop goto binop
...@@ -1157,17 +1154,15 @@ l0: ...@@ -1157,17 +1154,15 @@ l0:
l.prec = PCMP l.prec = PCMP
if c1 == '=' { if c1 == '=' {
c = LLE
l.op = OLE l.op = OLE
goto lx goto lx
} }
c = LLT
l.op = OLT l.op = OLT
case '=': case '=':
c1 = l.getr() c1 = l.getr()
if c1 == '=' { if c1 == '=' {
c = LEQ c = LOPER
l.prec = PCMP l.prec = PCMP
l.op = OEQ l.op = OEQ
goto lx goto lx
...@@ -1176,7 +1171,7 @@ l0: ...@@ -1176,7 +1171,7 @@ l0:
case '!': case '!':
c1 = l.getr() c1 = l.getr()
if c1 == '=' { if c1 == '=' {
c = LNE c = LOPER
l.prec = PCMP l.prec = PCMP
l.op = ONE l.op = ONE
goto lx goto lx
...@@ -1185,14 +1180,14 @@ l0: ...@@ -1185,14 +1180,14 @@ l0:
case '&': case '&':
c1 = l.getr() c1 = l.getr()
if c1 == '&' { if c1 == '&' {
c = LANDAND c = LOPER
l.prec = PANDAND l.prec = PANDAND
l.op = OANDAND l.op = OANDAND
goto lx goto lx
} }
if c1 == '^' { if c1 == '^' {
c = LANDNOT c = LOPER
op = OANDNOT op = OANDNOT
prec = PMUL prec = PMUL
goto binop goto binop
...@@ -1205,7 +1200,7 @@ l0: ...@@ -1205,7 +1200,7 @@ l0:
case '|': case '|':
c1 = l.getr() c1 = l.getr()
if c1 == '|' { if c1 == '|' {
c = LOROR c = LOPER
l.prec = POROR l.prec = POROR
l.op = OOROR l.op = OOROR
goto lx goto lx
...@@ -2259,44 +2254,37 @@ func lexfini() { ...@@ -2259,44 +2254,37 @@ func lexfini() {
} }
var lexn = map[rune]string{ var lexn = map[rune]string{
LANDAND: "ANDAND", LNAME: "NAME",
LANDNOT: "ANDNOT", LLITERAL: "LITERAL",
LASOP: "ASOP",
LOPER: "OPER",
LASOP: "ASOP",
LINCOP: "INCOP",
LCOLAS: "COLAS",
LCOMM: "COMM",
LDDD: "DDD",
LBREAK: "BREAK", LBREAK: "BREAK",
LCASE: "CASE", LCASE: "CASE",
LCHAN: "CHAN", LCHAN: "CHAN",
LCOLAS: "COLAS",
LCOMM: "<-",
LCONST: "CONST", LCONST: "CONST",
LCONTINUE: "CONTINUE", LCONTINUE: "CONTINUE",
LDDD: "...",
LDEFAULT: "DEFAULT", LDEFAULT: "DEFAULT",
LDEFER: "DEFER", LDEFER: "DEFER",
LELSE: "ELSE", LELSE: "ELSE",
LEQ: "EQ",
LFALL: "FALL", LFALL: "FALL",
LFOR: "FOR", LFOR: "FOR",
LFUNC: "FUNC", LFUNC: "FUNC",
LGE: "GE",
LGO: "GO", LGO: "GO",
LGOTO: "GOTO", LGOTO: "GOTO",
LGT: "GT",
LIF: "IF", LIF: "IF",
LIMPORT: "IMPORT", LIMPORT: "IMPORT",
LINCOP: "INCOP",
LINTERFACE: "INTERFACE", LINTERFACE: "INTERFACE",
LLE: "LE",
LLITERAL: "LITERAL",
LLSH: "LSH",
LLT: "LT",
LMAP: "MAP", LMAP: "MAP",
LNAME: "NAME",
LNE: "NE",
LOROR: "OROR",
LPACKAGE: "PACKAGE", LPACKAGE: "PACKAGE",
LRANGE: "RANGE", LRANGE: "RANGE",
LRETURN: "RETURN", LRETURN: "RETURN",
LRSH: "RSH",
LSELECT: "SELECT", LSELECT: "SELECT",
LSTRUCT: "STRUCT", LSTRUCT: "STRUCT",
LSWITCH: "SWITCH", LSWITCH: "SWITCH",
......
...@@ -92,14 +92,16 @@ func (p *parser) syntax_error(msg string) { ...@@ -92,14 +92,16 @@ func (p *parser) syntax_error(msg string) {
// determine token string // determine token string
var tok string var tok string
switch p.tok { switch p.tok {
case LLITERAL:
tok = litbuf
case LNAME: case LNAME:
if p.sym_ != nil && p.sym_.Name != "" { if p.sym_ != nil && p.sym_.Name != "" {
tok = p.sym_.Name tok = p.sym_.Name
} else { } else {
tok = "name" tok = "name"
} }
case LLITERAL:
tok = litbuf
case LOPER:
tok = goopnames[p.op]
case LASOP: case LASOP:
tok = goopnames[p.op] + "=" tok = goopnames[p.op] + "="
case LINCOP: case LINCOP:
...@@ -188,15 +190,22 @@ func tokstring(tok int32) string { ...@@ -188,15 +190,22 @@ func tokstring(tok int32) string {
} }
var tokstrings = map[int32]string{ var tokstrings = map[int32]string{
LLITERAL: "LLITERAL", LNAME: "NAME",
LASOP: "op=", LLITERAL: "LITERAL",
LCOLAS: ":=",
LOPER: "op",
LASOP: "op=",
LINCOP: "opop",
LCOLAS: ":=",
LCOMM: "<-",
LDDD: "...",
LBREAK: "break", LBREAK: "break",
LCASE: "case", LCASE: "case",
LCHAN: "chan", LCHAN: "chan",
LCONST: "const", LCONST: "const",
LCONTINUE: "continue", LCONTINUE: "continue",
LDDD: "...",
LDEFAULT: "default", LDEFAULT: "default",
LDEFER: "defer", LDEFER: "defer",
LELSE: "else", LELSE: "else",
...@@ -209,7 +218,6 @@ var tokstrings = map[int32]string{ ...@@ -209,7 +218,6 @@ var tokstrings = map[int32]string{
LIMPORT: "import", LIMPORT: "import",
LINTERFACE: "interface", LINTERFACE: "interface",
LMAP: "map", LMAP: "map",
LNAME: "LNAME",
LPACKAGE: "package", LPACKAGE: "package",
LRANGE: "range", LRANGE: "range",
LRETURN: "return", LRETURN: "return",
...@@ -218,20 +226,6 @@ var tokstrings = map[int32]string{ ...@@ -218,20 +226,6 @@ var tokstrings = map[int32]string{
LSWITCH: "switch", LSWITCH: "switch",
LTYPE: "type", LTYPE: "type",
LVAR: "var", LVAR: "var",
LANDAND: "&&",
LANDNOT: "&^",
LCOMM: "<-",
LEQ: "==",
LGE: ">=",
LGT: ">",
LIGNORE: "LIGNORE", // we should never see this one
LINCOP: "opop",
LLE: "<=",
LLSH: "<<",
LLT: "<",
LNE: "!=",
LOROR: "||",
LRSH: ">>",
} }
// usage: defer p.trace(msg)() // usage: defer p.trace(msg)()
......
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