Golang go/token.Token.Precedence function example

package go/token

Precedence returns the operator precedence of the binary operator op. If op is not a binary operator, the result is LowestPrecedence.

Golang go/token.Token.Precedence function usage example

 func diffPrec(expr ast.Expr, prec int) int {
  x, ok := expr.(*ast.BinaryExpr)
  if !ok || prec != x.Op.Precedence() {
 return 1
  }
  return 0
 }

References :

http://golang.org/pkg/go/token/#Token.Precedence

Advertisement