Files

64 lines
1.1 KiB
Go

package main
// Node represents an AST node.
type Node interface {
isNode()
}
type Expr interface {
Node
isExpr()
}
// BinaryExpr represents a binary operation.
type BinaryExpr struct {
Op string
Left Expr
Right Expr
}
func (e *BinaryExpr) isNode() {}
func (e *BinaryExpr) isExpr() {}
// UnaryExpr represents a unary operation (+, -, ~).
type UnaryExpr struct {
Op string
Expr Expr
}
func (e *UnaryExpr) isNode() {}
func (e *UnaryExpr) isExpr() {}
// NumberExpr represents a numeric literal.
type NumberExpr struct {
Value string // parsed as decimal later
}
func (e *NumberExpr) isNode() {}
func (e *NumberExpr) isExpr() {}
// IdentExpr represents an identifier (variable, unit, constant, or currency symbol).
type IdentExpr struct {
Name string
}
func (e *IdentExpr) isNode() {}
func (e *IdentExpr) isExpr() {}
// CallExpr represents a function call.
type CallExpr struct {
Func string
Args []Expr
}
func (e *CallExpr) isNode() {}
func (e *CallExpr) isExpr() {}
// StringExpr represents a string literal.
type StringExpr struct {
Value string
}
func (e *StringExpr) isNode() {}
func (e *StringExpr) isExpr() {}