37 lines
717 B
Go
37 lines
717 B
Go
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||
|
// All rights reserved.
|
||
|
|
||
|
// operand-expr.go
|
||
|
package expr
|
||
|
|
||
|
import "errors"
|
||
|
|
||
|
// -------- expr term
|
||
|
func newExprTerm(tk *Token) *term {
|
||
|
return &term{
|
||
|
tk: *tk,
|
||
|
class: classVar,
|
||
|
kind: kindUnknown,
|
||
|
parent: nil,
|
||
|
children: nil,
|
||
|
position: posLeaf,
|
||
|
priority: priValue,
|
||
|
evalFunc: evalExpr,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// -------- eval expr
|
||
|
func evalExpr(ctx exprContext, self *term) (v any, err error) {
|
||
|
if expr, ok := self.value().(Expr); ok {
|
||
|
v, err = expr.Eval(ctx, false)
|
||
|
} else {
|
||
|
err = errors.New("invalid body of function definition")
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// init
|
||
|
// func init() {
|
||
|
// registerTermConstructor(SymExpression, newExprTerm)
|
||
|
// }
|