mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-09-13 23:21:38 +00:00
good good study, day day up!
This commit is contained in:
40
vendor/gopl.io/ch7/eval/ast.go
generated
vendored
Normal file
40
vendor/gopl.io/ch7/eval/ast.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
|
||||
package eval
|
||||
|
||||
// An Expr is an arithmetic expression.
|
||||
type Expr interface {
|
||||
// Eval returns the value of this Expr in the environment env.
|
||||
Eval(env Env) float64
|
||||
// Check reports errors in this Expr and adds its Vars to the set.
|
||||
Check(vars map[Var]bool) error
|
||||
}
|
||||
|
||||
//!+ast
|
||||
|
||||
// A Var identifies a variable, e.g., x.
|
||||
type Var string
|
||||
|
||||
// A literal is a numeric constant, e.g., 3.141.
|
||||
type literal float64
|
||||
|
||||
// A unary represents a unary operator expression, e.g., -x.
|
||||
type unary struct {
|
||||
op rune // one of '+', '-'
|
||||
x Expr
|
||||
}
|
||||
|
||||
// A binary represents a binary operator expression, e.g., x+y.
|
||||
type binary struct {
|
||||
op rune // one of '+', '-', '*', '/'
|
||||
x, y Expr
|
||||
}
|
||||
|
||||
// A call represents a function call expression, e.g., sin(x).
|
||||
type call struct {
|
||||
fn string // one of "pow", "sin", "sqrt"
|
||||
args []Expr
|
||||
}
|
||||
|
||||
//!-ast
|
Reference in New Issue
Block a user