blob: 627a6234277254b8dbaf70a5143fb0c5ecdf3bd4 [file] [log] [blame]
package ast
import "matheval/token"
// Node is the interface all AST nodes implement.
// The unexported marker method seals the interface — only types
// in this package can implement it.
type Node interface {
node() // sealed marker
}
// NumberLit represents a numeric literal (e.g. 3.14).
type NumberLit struct {
Value float64
}
func (*NumberLit) node() {}
// BinaryExpr represents a binary operation (e.g. 1 + 2).
type BinaryExpr struct {
Op token.Type // Plus, Minus, Star, Slash
Left Node
Right Node
}
func (*BinaryExpr) node() {}
// Ident represents a variable reference (e.g. x, y).
type Ident struct {
Name string
}
func (*Ident) node() {}
// FuncCall represents a function call (e.g. f(1, 2+3)).
type FuncCall struct {
Name string
Args []Node
}
func (*FuncCall) node() {}
// Statement is the interface for top-level REPL input.
// A line is either an expression to evaluate or a function definition.
// The unexported marker method seals the interface.
type Statement interface {
stmt() // sealed marker
}
// ExprStmt wraps an expression as a top-level statement.
type ExprStmt struct {
Expr Node
}
func (*ExprStmt) stmt() {}
// FuncDef represents a function definition (e.g. f(x, y) = x + y).
type FuncDef struct {
Name string
Params []string
Body Node
}
func (*FuncDef) stmt() {}