You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
1.5 KiB
Go
90 lines
1.5 KiB
Go
package ast
|
|
|
|
import "golox/token"
|
|
|
|
type ExprVisitor[T any] interface {
|
|
VisitErrorExpr(ee *ErrorExpr) T
|
|
VisitAssignExpr(ae *AssignExpr) T
|
|
VisitBinaryExpr(be *BinaryExpr) T
|
|
VisitGroupingExpr(ge *GroupingExpr) T
|
|
VisitLiteralExpr(le *LiteralExpr) T
|
|
VisitLogicalExpr(le *LogicalExpr) T
|
|
VisitUnaryExpr(ue *UnaryExpr) T
|
|
VisitVariableExpr(ve *VariableExpr) T
|
|
}
|
|
|
|
type Expr interface {
|
|
Accept(visitor ExprVisitor[any]) any
|
|
}
|
|
|
|
type ErrorExpr struct {
|
|
Value string
|
|
}
|
|
|
|
func (ee *ErrorExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitErrorExpr(ee)
|
|
}
|
|
|
|
type AssignExpr struct {
|
|
Name token.Token
|
|
Value Expr
|
|
}
|
|
|
|
func (ae *AssignExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitAssignExpr(ae)
|
|
}
|
|
|
|
type BinaryExpr struct {
|
|
Left Expr
|
|
Operator token.Token
|
|
Right Expr
|
|
}
|
|
|
|
func (be *BinaryExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitBinaryExpr(be)
|
|
}
|
|
|
|
type GroupingExpr struct {
|
|
Expression Expr
|
|
}
|
|
|
|
func (ge *GroupingExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitGroupingExpr(ge)
|
|
}
|
|
|
|
type LiteralExpr struct {
|
|
Value any
|
|
}
|
|
|
|
func (le *LiteralExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitLiteralExpr(le)
|
|
}
|
|
|
|
type LogicalExpr struct {
|
|
Left Expr
|
|
Operator token.Token
|
|
Right Expr
|
|
}
|
|
|
|
func (le *LogicalExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitLogicalExpr(le)
|
|
}
|
|
|
|
type UnaryExpr struct {
|
|
Operator token.Token
|
|
Right Expr
|
|
}
|
|
|
|
func (ue *UnaryExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitUnaryExpr(ue)
|
|
}
|
|
|
|
type VariableExpr struct {
|
|
Name token.Token
|
|
}
|
|
|
|
func (ve *VariableExpr) Accept(v ExprVisitor[any]) any {
|
|
return v.VisitVariableExpr(ve)
|
|
}
|
|
|