cmd/compile, go/parser: simpler binary expression parsing

The existing nested loops are too tricky for me to grok and don't seem
necessary.

Change-Id: I75c65c8470b799d6f4cfb05bb1b4796c5d7d32e7
Reviewed-on: https://go-review.googlesource.com/19927
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2016-02-25 17:16:42 -08:00
parent c8579e57cb
commit 49d1e30710
2 changed files with 17 additions and 24 deletions

View file

@ -1142,17 +1142,14 @@ func (p *parser) bexpr(prec int) *Node {
// don't trace bexpr - only leads to overly nested trace output
x := p.uexpr()
t := prectab[p.tok]
for tprec := t.prec; tprec >= prec; tprec-- {
for tprec == prec {
p.next()
y := p.bexpr(t.prec + 1)
x = Nod(t.op, x, y)
t = prectab[p.tok]
tprec = t.prec
for {
t := prectab[p.tok]
if t.prec < prec {
return x
}
p.next()
x = Nod(t.op, x, p.bexpr(t.prec+1))
}
return x
}
func (p *parser) expr() *Node {