expr.go 834 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package expr
  2. import "reflect"
  3. // A Var identifies a variable, e.g., x.
  4. type Var string
  5. // A literal is a numeric constant, e.g., 3.141.
  6. type literal struct {
  7. value interface{}
  8. }
  9. // An Expr is an arithmetic expression.
  10. type Expr interface {
  11. // Eval returns the value of this Expr in the environment env.
  12. Eval(env Env) reflect.Value
  13. // Check reports errors in this Expr and adds its Vars to the set.
  14. Check(vars map[Var]interface{}) error
  15. }
  16. // A unary represents a unary operator expression, e.g., -x.
  17. type unary struct {
  18. op string // one of '+', '-', '!', '~'
  19. x Expr
  20. }
  21. // A binary represents a binary operator expression, e.g., x+y.
  22. type binary struct {
  23. op string
  24. x, y Expr
  25. }
  26. // A call represents a function call expression, e.g., sin(x).
  27. type call struct {
  28. fn string // one of "pow", "sin", "sqrt"
  29. args []Expr
  30. }