27. *ast.BasicLit
package ast // import "go/ast"
type BasicLit struct {
ValuePos token.Pos // literal position
Kind token.Token // token.INT, token.FLOAT, token.IMAG, token.CHAR, or token.STRING
Value string // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 2.4i, 'a', 'x7f', "foo" or `mno`
}
func (x *BasicLit) End() token.Pos
func (x *BasicLit) Pos() token.Pos
28. *ast.ParenExpr
package ast // import "go/ast"
type ParenExpr struct {
Lparen token.Pos // position of "("
X Expr // parenthesized expression
Rparen token.Pos // position of ")"
}
func (x *ParenExpr) End() token.Pos
func (x *ParenExpr) Pos() token.Pos
29. *ast.UnaryExpr
package ast // import "go/ast"
type UnaryExpr struct {
OpPos token.Pos // position of Op
Op token.Token // operator
X Expr // operand
}
func (x *UnaryExpr) End() token.Pos
func (x *UnaryExpr) Pos() token.Pos
30. *ast.BinaryExpr
package ast // import "go/ast"
type BinaryExpr struct {
X Expr // left operand
OpPos token.Pos // position of Op
Op token.Token // operator
Y Expr // right operand
}
func (x *BinaryExpr) End() token.Pos
func (x *BinaryExpr) Pos() token.Pos
38. evaluateBinaryExpr
func evaluateBinaryExpr(expr *ast.BinaryExpr) float64{
x := evaluateExpr(expr.X)
y := evaluateExpr(expr.Y)
switch expr.Op {
case token.ADD:
return x + y
case token.SUB:
return x - y
case token.MUL:
return x * y
case token.QUO:
return x / y
case token.REM:
return float64(int(x) % int(y))
default:
panic("binaryExpr error")
}
}